diff --git a/g/os/gtime/gtime_time.go b/g/os/gtime/gtime_time.go index c334f8b23..a02393e75 100644 --- a/g/os/gtime/gtime_time.go +++ b/g/os/gtime/gtime_time.go @@ -62,6 +62,9 @@ func NewFromStrLayout (str string, layout string) *Time { // 时间戳转换为时间对象,时间戳支持到纳秒的数值 func NewFromTimeStamp (timestamp int64) *Time { + if timestamp == 0 { + return &Time {} + } for timestamp < 1e18 { timestamp *= 10 } diff --git a/g/util/gconv/gconv_time.go b/g/util/gconv/gconv_time.go index 42a13712b..7211c368b 100644 --- a/g/util/gconv/gconv_time.go +++ b/g/util/gconv/gconv_time.go @@ -25,6 +25,9 @@ func TimeDuration(i interface{}) time.Duration { // 将变量i转换为time.Time类型 func GTime(i interface{}, format...string) *gtime.Time { s := String(i) + if len(s) == 0 { + return gtime.New() + } // 优先使用用户输入日期格式进行转换 if len(format) > 0 { t, _ := gtime.StrToTimeFormat(s, format[0]) diff --git a/g/util/gstr/gstr.go b/g/util/gstr/gstr.go index 4f47b708f..b1b0772a2 100644 --- a/g/util/gstr/gstr.go +++ b/g/util/gstr/gstr.go @@ -96,6 +96,10 @@ func IsLetterUpper(b byte) bool { // 判断锁给字符串是否为数字 func IsNumeric(s string) bool { + length := len(s) + if length == 0 { + return false + } for i := 0; i < len(s); i++ { if s[i] < byte('0') || s[i] > byte('9') { return false diff --git a/geg/other/test2.go b/geg/other/test2.go index 32c753eec..2c541bd7e 100644 --- a/geg/other/test2.go +++ b/geg/other/test2.go @@ -1,22 +1,19 @@ package main import ( - "container/list" - "gitee.com/johng/gf/g/os/glog" + "fmt" + "gitee.com/johng/gf/g/util/gconv" "time" ) func main(){ - list := list.New() - glog.Println("start1") - for i := 0; i < 10000000; i++ { - list.PushBack(i) + type Test struct { + Date time.Time `json:"date"` } - glog.Println("end1") - - glog.Println("start2") - for e := list.Front(); e != nil; e = e.Next() { - time.Sleep(25*time.Nanosecond) + o := new(Test) + m := map[string]interface{}{ + "Date" : "", } - glog.Println("end2") + gconv.Struct(m, o) + fmt.Println(o) }