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 0aeaeb4 commit c9bd6c6
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)
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeLayout, t.loc.String())
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)
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeMilliLayout, t.loc.String())
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)
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeMicroLayout, t.loc.String())
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)
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeNanoLayout, t.loc.String())
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)
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateLayout, t.loc.String())
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)
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateMilliLayout, t.loc.String())
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)
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateMicroLayout, t.loc.String())
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)
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateNanoLayout, t.loc.String())
if c.Error == nil {
*t = DateNano{c}
}
Expand Down

0 comments on commit c9bd6c6

Please # to comment.