Skip to content

Commit

Permalink
fix: fix unix to time
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangwanpeng committed Jul 19, 2023
1 parent d0291e3 commit a9e225d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions internal/common/utils/time_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"github.com/jinzhu/now"
)

const (
// 1990-01-01 00:00:00
unixMilli1990 = 631152000000
)

func ParseTime(value any) (time.Time, error) {
var t time.Time
var err error
Expand All @@ -30,13 +35,13 @@ func ParseTime(value any) (time.Time, error) {
}

func UnixToTime(n int64) time.Time {
if n > 1e18 {
if n > unixMilli1990*1000000 {
return time.Unix(0, n)
}
if n > 1e15 {
if n > unixMilli1990*1000 {
return time.UnixMicro(n)
}
if n > 1e12 {
if n > unixMilli1990 {
return time.UnixMilli(n)
}
return time.Unix(n, 0)
Expand Down

0 comments on commit a9e225d

Please sign in to comment.