From 42c47057789c6ab7b81e64623e76bcadac45aa14 Mon Sep 17 00:00:00 2001 From: Peleus <245629560@qq.com> Date: Wed, 6 Sep 2023 20:33:56 +0800 Subject: [PATCH] Fix bug with lost time zone after `marshal/unmarshal` --- json.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/json.go b/json.go index 29e53214..0d9393f8 100644 --- a/json.go +++ b/json.go @@ -87,7 +87,7 @@ func (t DateTime) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements the interface json.Unmarshal for DateTime struct. // 实现 UnmarshalJSON 接口 func (t *DateTime) UnmarshalJSON(b []byte) error { - c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeLayout, t.loc.String()) + c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeLayout, t.Location()) if c.Error == nil { *t = DateTime{c} } @@ -109,7 +109,7 @@ func (t DateTimeMilli) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements the interface json.Unmarshal for DateTimeMilli struct. // 实现 UnmarshalJSON 接口 func (t *DateTimeMilli) UnmarshalJSON(b []byte) error { - c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeMilliLayout, t.loc.String()) + c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeMilliLayout, t.Location()) if c.Error == nil { *t = DateTimeMilli{c} } @@ -131,7 +131,7 @@ func (t DateTimeMicro) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements the interface json.Unmarshal for DateTimeMicro struct. // 实现 UnmarshalJSON 接口 func (t *DateTimeMicro) UnmarshalJSON(b []byte) error { - c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeMicroLayout, t.loc.String()) + c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeMicroLayout, t.Location()) if c.Error == nil { *t = DateTimeMicro{c} } @@ -153,7 +153,7 @@ func (t DateTimeNano) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements the interface json.Unmarshal for DateTimeNano struct. // 实现 UnmarshalJSON 接口 func (t *DateTimeNano) UnmarshalJSON(b []byte) error { - c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeNanoLayout, t.loc.String()) + c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeNanoLayout, t.Location()) if c.Error == nil { *t = DateTimeNano{c} } @@ -175,7 +175,7 @@ func (t Date) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements the interface json.Unmarshal for Date struct. // 实现 UnmarshalJSON 接口 func (t *Date) UnmarshalJSON(b []byte) error { - c := ParseByLayout(string(bytes.Trim(b, `"`)), DateLayout, t.loc.String()) + c := ParseByLayout(string(bytes.Trim(b, `"`)), DateLayout, t.Location()) if c.Error == nil { *t = Date{c} } @@ -197,7 +197,7 @@ func (t DateMilli) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements the interface json.Unmarshal for DateMilli struct. // 实现 UnmarshalJSON 接口 func (t *DateMilli) UnmarshalJSON(b []byte) error { - c := ParseByLayout(string(bytes.Trim(b, `"`)), DateMilliLayout, t.loc.String()) + c := ParseByLayout(string(bytes.Trim(b, `"`)), DateMilliLayout, t.Location()) if c.Error == nil { *t = DateMilli{c} } @@ -219,7 +219,7 @@ func (t DateMicro) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements the interface json.Unmarshal for DateMicro struct. // 实现 UnmarshalJSON 接口 func (t *DateMicro) UnmarshalJSON(b []byte) error { - c := ParseByLayout(string(bytes.Trim(b, `"`)), DateMicroLayout, t.loc.String()) + c := ParseByLayout(string(bytes.Trim(b, `"`)), DateMicroLayout, t.Location()) if c.Error == nil { *t = DateMicro{c} } @@ -241,7 +241,7 @@ func (t DateNano) MarshalJSON() ([]byte, error) { // UnmarshalJSON implements the interface json.Unmarshal for DateNano struct. // 实现 UnmarshalJSON 接口 func (t *DateNano) UnmarshalJSON(b []byte) error { - c := ParseByLayout(string(bytes.Trim(b, `"`)), DateNanoLayout, t.loc.String()) + c := ParseByLayout(string(bytes.Trim(b, `"`)), DateNanoLayout, t.Location()) if c.Error == nil { *t = DateNano{c} }