-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os/gtime: There is a bug in converting string to gtime.Time #3558
Comments
在这里记录一下我是怎么发现这个bug的吧,起因是我在 #3557 中给底层重新实现类型转换的时候发现的, 期初我以为是我的问题,我在我的本地环境又调试了一遍没发现什么问题, 这时候我已经发现可能是时区导致的问题了,于是我找到ci测试环境的mysql版本5.7.39,在我的本地装了一个同版本的 /*
CREATE TABLE `timezone` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`datetime` date DEFAULT NULL,
KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
*/
table := vm3306.Model("timezone")
_, err = table.Data(TimeZone{
DateTime: gtime.NewFromStr("1880-10-24"),
}).Insert()
record, err := table.One() 在查询的底层加一个打印的 输出的结果 可以和第一张图红圈上面的那个date做对比,上面图片的时区是UTC+0805,而这里的是+0800 CST 其实就是UTC+0800 但是我在 #3557 中对于实现了sql.Scanner接口的类型,统一使用了sql.RawBytes接收,恰好gtime.Time实现了这个接口, 这样就导致1880-10-24 00:00:00+08:05 解析后变成了1880-10-23 15:55:00Z,loc也是nil,等同于UTC+0 这样的实现其实是错误的,对比同样字符串的看下go标准库的解析 由于gtime.Time丢失了时区信息,导致日期格式化Y-m-d的时候变成了1880-10-23 |
Go version
1.22
GoFrame version
2.7.0
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
What did you see happen?
What did you expect to see?
The text was updated successfully, but these errors were encountered: