From 07c7a628d142af6f6172b6863515b38ac9cc836a Mon Sep 17 00:00:00 2001 From: hoteas <等> Date: Tue, 14 Jun 2022 09:52:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0time=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/map.go | 2 +- common/obj.go | 2 +- common/objtoobj.go | 29 ++++++++++++++++------------- common/slice.go | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/common/map.go b/common/map.go index ee21637..35ab73b 100644 --- a/common/map.go +++ b/common/map.go @@ -102,7 +102,7 @@ func (that Map) GetBool(key string, err ...*Error) bool { } -func (that Map) GetTime(key string, err ...*Error) time.Time { +func (that Map) GetTime(key string, err ...*Error) *time.Time { v := ObjToTime((that)[key], err...) return v diff --git a/common/obj.go b/common/obj.go index c4dc941..83aff56 100644 --- a/common/obj.go +++ b/common/obj.go @@ -20,7 +20,7 @@ func (that *Obj) ToInt(err ...Error) int { return ObjToInt(that.Data, &that.Error) } -func (that *Obj) ToTime(err ...Error) time.Time { +func (that *Obj) ToTime(err ...Error) *time.Time { if len(err) != 0 { that.Error = err[0] } diff --git a/common/objtoobj.go b/common/objtoobj.go index 5fb9b54..ee40907 100644 --- a/common/objtoobj.go +++ b/common/objtoobj.go @@ -97,7 +97,7 @@ func ObjToSlice(obj interface{}, e ...*Error) Slice { return v } -func ObjToTime(obj interface{}, e ...*Error) time.Time { +func ObjToTime(obj interface{}, e ...*Error) *time.Time { tInt := ObjToInt64(obj) //字符串类型,只支持标准mysql datetime格式 @@ -107,27 +107,27 @@ func ObjToTime(obj interface{}, e ...*Error) time.Time { if len(tStr) > 18 { t, e := time.Parse("2006-01-02 15:04:05", tStr) if e == nil { - return t + return &t } } else if len(tStr) > 15 { t, e := time.Parse("2006-01-02 15:04", tStr) if e == nil { - return t + return &t } } else if len(tStr) > 12 { t, e := time.Parse("2006-01-02 15", tStr) if e == nil { - return t + return &t } } else if len(tStr) > 9 { t, e := time.Parse("2006-01-02", tStr) if e == nil { - return t + return &t } } else if len(tStr) > 6 { t, e := time.Parse("2006-01", tStr) if e == nil { - return t + return &t } } @@ -135,25 +135,28 @@ func ObjToTime(obj interface{}, e ...*Error) time.Time { //纳秒级别 if len(ObjToStr(tInt)) > 16 { - - return time.Time{}.Add(time.Nanosecond * time.Duration(tInt)) + t := time.Time{}.Add(time.Nanosecond * time.Duration(tInt)) + return &t //微秒级别 } else if len(ObjToStr(tInt)) > 13 { - return time.Time{}.Add(time.Microsecond * time.Duration(tInt)) + t := time.Time{}.Add(time.Microsecond * time.Duration(tInt)) + return &t //毫秒级别 } else if len(ObjToStr(tInt)) > 10 { - return time.Time{}.Add(time.Millisecond * time.Duration(tInt)) + t := time.Time{}.Add(time.Millisecond * time.Duration(tInt)) + return &t //秒级别 } else if len(ObjToStr(tInt)) > 9 { - return time.Time{}.Add(time.Second * time.Duration(tInt)) + t := time.Time{}.Add(time.Second * time.Duration(tInt)) + return &t } else if len(ObjToStr(tInt)) > 3 { t, e := time.Parse("2006", ObjToStr(tInt)) if e == nil { - return t + return &t } } - return time.Time{} + return &time.Time{} } func ObjToFloat64(obj interface{}, e ...*Error) float64 { diff --git a/common/slice.go b/common/slice.go index dede608..b554a5c 100644 --- a/common/slice.go +++ b/common/slice.go @@ -15,7 +15,7 @@ func (that Slice) GetString(key int, err ...*Error) string { return ObjToStr((that)[key]) } -func (that Slice) GetTime(key int, err ...*Error) time.Time { +func (that Slice) GetTime(key int, err ...*Error) *time.Time { v := ObjToTime((that)[key], err...) return v