gf icon indicating copy to clipboard operation
gf copied to clipboard

os/gtime: [ORM] result 在 Structs 会丢时区,然后以当前系统的时区处理了 [发呆]

Open ToQuery opened this issue 3 months ago • 6 comments

Go version

go version go1.25.1 darwin/arm64

GoFrame version

v2.9.3

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

        result, err := db.Query(ctx, "SELECT NOW()")
	if err != nil {
		return nil, err
	}

	gtimeVal := result[0].Map()["now"].(*gtime.Time)
	name1, offaet1 := gtimeVal.Zone()
	fmt.Println("时区:", name1, offaet1/3600)
	fmt.Println("数据库时间:", gtimeVal)

	// 查询当前时间
	var nowResult []time.Time
	err = result.Structs(&nowResult)
	if err != nil {
		return nil, err
	}
	now := nowResult[0]
	name2, offaet2 := now.Zone()
	fmt.Println("Structs后 时区:", name2, offaet2/3600)
	fmt.Println("Structs后 数据库时间:", now)

What did you see happen?

SELECT NOW() 时区: GMT 0 数据库时间: 2025-09-15 07:45:40

Structs后 时区: CST 8 Structs后 数据库时间: 2025-09-15 07:45:40 +0800 CST

What did you expect to see?

orm 的 result 在 Structs 会丢时区,然后以当前系统的时区处理了

Structs后 数据库时间: 2025-09-15 15:45:40 +0800 CST

ToQuery avatar Sep 15 '25 07:09 ToQuery

result.Structs 前 2025-09-15 07:45:40 +0000 // 正确 result.Structs 后 2025-09-15 07:45:40 +0800 // 错误

ToQuery avatar Sep 15 '25 08:09 ToQuery

把图片也贴一下,方便分析 @ToQuery

houseme avatar Sep 16 '25 05:09 houseme

Image Image

ToQuery avatar Sep 16 '25 05:09 ToQuery

@ToQuery 你后续可以更加一下pr的内容,以及补充一下具体的错误描述信息 #4432

houseme avatar Sep 16 '25 08:09 houseme

现在您那边复现了么?

ToQuery avatar Sep 16 '25 08:09 ToQuery

github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.9.3
github.com/gogf/gf/v2 v2.9.4-0.20250916085609-118c4834511d
Image

预期

(如上图) 原始值(gtimeVal):2025-09-16 11:32:42.878465 +0000 ❌ 错误Structs值(now):2025-09-16 11:32:42 +0800 ✔ 预期Structs值(now):2025-09-16 11:32:42 +0000

ToQuery avatar Sep 16 '25 12:09 ToQuery

@ToQuery 我没看明白你的逻辑,我在我的电脑上没复现出来,两次输出结果都是+0800 CST,select now的结果是多个的吗,好像只有一个吧,

wln32 avatar Dec 14 '25 21:12 wln32