mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
fix(os/gtime): add handling for nil time pointers to avoid causing panic (#4323)
from https://github.com/gogf/gf/pull/4322 Fixes https://github.com/gogf/gf/issues/4307
This commit is contained in:
@ -36,8 +36,11 @@ func New(param ...interface{}) *Time {
|
||||
switch r := param[0].(type) {
|
||||
case time.Time:
|
||||
return NewFromTime(r)
|
||||
|
||||
case *time.Time:
|
||||
return NewFromTime(*r)
|
||||
if r != nil {
|
||||
return NewFromTime(*r)
|
||||
}
|
||||
|
||||
case Time:
|
||||
return &r
|
||||
|
||||
@ -71,3 +71,13 @@ func Test_Issue3558(t *testing.T) {
|
||||
t.Assert(gfTimeFormat, stdTimeFormat)
|
||||
})
|
||||
}
|
||||
|
||||
// Test_Issue4307 https://github.com/gogf/gf/issues/4307
|
||||
func Test_Issue4307(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var timeNil *time.Time = nil
|
||||
// This should not panic.
|
||||
gfTime := gtime.New(timeNil)
|
||||
t.AssertNil(gfTime)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user