Repository: gogf/gf

Issue:
os/gtime: GTime invalid memory address or nil pointer
### Go version

go1.2.=4.3

### GoFrame version

v2.8.3

### Can this bug be reproduced with the latest release?

Option Yes

### What did you do?

type GtimeTest struct {
	ChildCommitTime *time.Time `json:"childCommitTime"`
}

func main() {
	gtimeTest := &GtimeTest{}
	gTime := gconv.GTime(gtimeTest.ChildCommitTime)
	fmt.Println(gTime)
}

### What did you see happen?

<img width="827" alt="Image" src="https://github.com/user-attachments/assets/9626c0f3-59c9-4576-a6c4-0360c0d85123" />

### What did you expect to see?

return nil

Hints from issue comments:

Solution patch:
diff --git a/os/gtime/gtime_time.go b/os/gtime/gtime_time.go
index 388c4248f..9e6b291b8 100644
--- a/os/gtime/gtime_time.go
+++ b/os/gtime/gtime_time.go
@@ -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



Test patch:
diff --git a/os/gtime/gtime_z_unit_issue_test.go b/os/gtime/gtime_z_unit_issue_test.go
index 6650c5aa8..2be17abd9 100644
--- a/os/gtime/gtime_z_unit_issue_test.go
+++ b/os/gtime/gtime_z_unit_issue_test.go
@@ -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)
+	})
+}