Skip to content

Commit 1c830e8

Browse files
committed
datetime utc in json
1 parent 60740e2 commit 1c830e8

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

generator/client/golang/templates/queryx/datetime.gotmpl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (d Datetime) MarshalJSON() ([]byte, error) {
7575
if d.Null {
7676
return json.Marshal(nil)
7777
}
78-
return json.Marshal(d.Val)
78+
return json.Marshal(d.Val.UTC())
7979
}
8080

8181
// UnmarshalJSON implements the json.Unmarshaler interface.
@@ -91,7 +91,12 @@ func (d *Datetime) UnmarshalJSON(data []byte) error {
9191
if err != nil {
9292
return err
9393
}
94-
d.Val = t
94+
95+
location, err := loadLocation()
96+
if err != nil {
97+
return err
98+
}
99+
d.Val = t.In(location)
95100

96101
return nil
97102
}

generator/client/golang/templates/queryx/datetime_test.gotmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestDatetimeJSON(t *testing.T) {
2525
}
2626
x := NewDatetime("2012-12-12 11:10:09")
2727
y := NewNullableDatetime(nil)
28-
s := `{"x":"2012-12-12T11:10:09+08:00","y":null}`
28+
s := `{"x":"2012-12-12T03:10:09Z","y":null}`
2929

3030
f1 := Foo{X: x, Y: y}
3131
b, err := json.Marshal(f1)

internal/integration/postgresql.hcl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
database "db" {
22
adapter = "postgresql"
3+
time_zone = "Asia/Shanghai"
34

45
config "test" {
56
url = "postgres://postgres:postgres@localhost:5432/queryx_test?sslmode=disable"

0 commit comments

Comments
 (0)