sqlc
sqlc copied to clipboard
The parsed default timezone of timestamp fields must be "UTC" not ""
Version
1.26.0
What happened?
I will try to show the bug (I can't say it's a bug , as it can fixed by just adjusting the label of the location object used) as brief as possible .
this test code
arg.SnapDate = util.RandomDate().Round(time.Second).UTC()
require.Equal(t, arg.SnapDate, snapshot.SnapDate)
arg.SnapDate is generated randomly , it's referred to be the actual value snapshot.SnapDate is marshaled by SQLC compiler .
will result the following error
Error: ``` Not equal: expected: time.Date(2028, time.February, 25, 0, 0, 0, 0, time.Location("")) actual : time.Date(2028, time.February, 25, 0, 0, 0, 0, time.Location(""))
Diff:
--- Expected
+++ Actual
@@ -1,2 +1,2 @@
-(time.Time) 2028-02-25 00:00:00 +0000 UTC
+(time.Time) 2028-02-25 00:00:00 +0000 +0000
I inspected the go time.Location object of both fields and found the following:
SQLC parsed the timestamp with `time.FixedZone("", 0)` i guess without a name which golang interprets it's name as "" and actually it's "UTC" .
Now I have to do something like :
loc := time.FixedZone("", 0)
res := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, loc).Round(time.Second)
each time I deal with timestamps .
Kindly tell me where exactly in SQLC source code . I can replace that FixedZone location with UTC location instead . so it makes my code more cleaner .
### Relevant log output
_No response_
### Database schema
_No response_
### SQL queries
_No response_
### Configuration
_No response_
### Playground URL
_No response_
### What operating system are you using?
_No response_
### What database engines are you using?
_No response_
### What type of code are you generating?
_No response_