Skip to content

Commit

Permalink
Fix bug with lost time zone after marshal/unmarshal
Browse files Browse the repository at this point in the history
  • Loading branch information
gouguoyin committed Sep 6, 2023
1 parent c9bd6c6 commit 42c4705
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand All @@ -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}
}
Expand All @@ -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}
}
Expand All @@ -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}
}
Expand All @@ -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}
}
Expand All @@ -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}
}
Expand All @@ -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}
}
Expand All @@ -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}
}
Expand Down

0 comments on commit 42c4705

Please # to comment.