os/gtime: [ORM] result 在 Structs 会丢时区,然后以当前系统的时区处理了 [发呆]
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
result.Structs 前 2025-09-15 07:45:40 +0000 // 正确 result.Structs 后 2025-09-15 07:45:40 +0800 // 错误
把图片也贴一下,方便分析 @ToQuery
@ToQuery 你后续可以更加一下pr的内容,以及补充一下具体的错误描述信息 #4432
现在您那边复现了么?
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.9.3
github.com/gogf/gf/v2 v2.9.4-0.20250916085609-118c4834511d
预期
(如上图) 原始值(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 我没看明白你的逻辑,我在我的电脑上没复现出来,两次输出结果都是+0800 CST,select now的结果是多个的吗,好像只有一个吧,