sqlite数据库时区问题,engine.TZLocation与engine.DatabaseTZ设置的时机不同,时间打印结果会不同 #1612
Labels
No Label
backport/done
backport/v1
blocked
db
oracle
db
sqlserver
duplicate
feature
cache
frontport/done
frontport/main
invalid
kind
breaking
kind
bug
kind
build
kind
dependencies
kind
docs
kind
driver
kind
enhancement
kind
feature
kind
performance
kind
proposal
kind
question
kind
refactor
kind
testing
need
feedback
need
test
proposal:accepted
RaspBerry Pi
regression
skip-changelog
upstream
wip
wontfix
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: xorm/xorm#1612
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
复现代码
问题分析
时间的入库: xorm在插入时间的时候会进行格式化,此时xorm会丢失掉时区相关的信息,因为格式化的格式是:
2006-01-02 15:04:05
,不包含时区。时间的出库: 当sqlite3拿到数据的时候会进行解析,因为xorm格式化的时候丢失了时区,此时sqlite3是按utc时区进行解析,然后sqlite3再根据打开时候的配置
_loc
的时区进行转换,这个时候时间就会产生了异常,然后xorm拿到的时间就是异常的,此时xorm也会判断sqlite3吐出的时区是否和配置的engine.DatabaseTZ
相等,如果不相等也会进行转换。Which version are you using? Once you set
engine.DatabaseTZ
, the previous data on database will not be changed with the new time one.版本:xorm.io/xorm v0.8.2
上面的例子,可以复现我的问题,数据每次都是新的,因为
os.Remove("test.db")
sqlite3 has a default DatabaseTZ as UTC, but since you override it. I think this should not an issue.
Could you help to confirm this is still a problem?
I think this has been resolved.