Skip to content

Commit

Permalink
Fix Time,TimeMilli,TimeMicro,TimeNano UnmarshalJSON bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gouguoyin committed Dec 2, 2024
1 parent e9eff84 commit 230a57b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,8 @@ func (t *Time) UnmarshalJSON(b []byte) error {
return nil
}
year, month, day := Now().Date()
c := ParseByLayout(fmt.Sprintf("%d-%d-%d %s", year, month, day, value), DateTimeLayout)
c := ParseByLayout(fmt.Sprintf("%d-%02d-%02d %s", year, month, day, value), DateTimeLayout)
fmt.Println("c", c)
if c.Error == nil {
*t = NewTime(c)
}
Expand Down Expand Up @@ -491,7 +492,7 @@ func (t *TimeMilli) UnmarshalJSON(b []byte) error {
return nil
}
year, month, day := Now().Date()
c := ParseByLayout(fmt.Sprintf("%d-%d-%d %s", year, month, day, value), DateTimeMilliLayout)
c := ParseByLayout(fmt.Sprintf("%d-%02d-%02d %s", year, month, day, value), DateTimeMilliLayout)
if c.Error == nil {
*t = NewTimeMilli(c)
}
Expand Down Expand Up @@ -536,7 +537,7 @@ func (t *TimeMicro) UnmarshalJSON(b []byte) error {
return nil
}
year, month, day := Now().Date()
c := ParseByLayout(fmt.Sprintf("%d-%d-%d %s", year, month, day, value), DateTimeMicroLayout)
c := ParseByLayout(fmt.Sprintf("%d-%02d-%02d %s", year, month, day, value), DateTimeMicroLayout)
if c.Error == nil {
*t = NewTimeMicro(c)
}
Expand Down Expand Up @@ -581,7 +582,7 @@ func (t *TimeNano) UnmarshalJSON(b []byte) error {
return nil
}
year, month, day := Now().Date()
c := ParseByLayout(fmt.Sprintf("%d-%d-%d %s", year, month, day, value), DateTimeNanoLayout)
c := ParseByLayout(fmt.Sprintf("%d-%02d-%02d %s", year, month, day, value), DateTimeNanoLayout)
if c.Error == nil {
*t = NewTimeNano(c)
}
Expand Down

0 comments on commit 230a57b

Please sign in to comment.