Skip to content

Commit ff21c7e

Browse files
committed
Merge branch 'v2.6.x'
2 parents 0df7eb9 + 2420a14 commit ff21c7e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

getter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
// StdTime gets standard time.Time.
88
// 获取标准 time.Time
99
func (c *Carbon) StdTime() time.Time {
10+
if c.IsInvalid() {
11+
return time.Time{}
12+
}
1013
if c.loc == nil {
1114
return c.time
1215
}

getter_unit_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ func TestCarbon_StdTime(t *testing.T) {
2828
c := Parse("2020-08-05", PRC)
2929
assert.Equal(t, "2020-08-05 00:00:00 +0800 CST", c.StdTime().String())
3030
})
31+
32+
// https://github.com/dromara/carbon/issues/294
33+
t.Run("issue294", func(t *testing.T) {
34+
assert.Equal(t, "0001-01-01 00:00:00 +0000 UTC", Parse("").StdTime().String())
35+
assert.Equal(t, "0001-01-01 00:00:00 +0000 UTC", Parse("0").StdTime().String())
36+
assert.Equal(t, "0001-01-01 00:00:00 +0000 UTC", Parse("xxx").StdTime().String())
37+
})
3138
}
3239

3340
func TestCarbon_DaysInYear(t *testing.T) {

0 commit comments

Comments
 (0)