Skip to content

Commit

Permalink
Merge pull request #140 from prashantv/iszero
Browse files Browse the repository at this point in the history
Revert "use pointer receivers on the IsZero variants for DateTime"
  • Loading branch information
casualjim authored Jan 31, 2025
2 parents 75847d1 + aaf748e commit 66719db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
14 changes: 4 additions & 10 deletions time.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,13 @@ func (t DateTime) String() string {
}

// IsZero returns whether the date time is a zero value
func (t *DateTime) IsZero() bool {
if t == nil {
return true
}
return time.Time(*t).IsZero()
func (t DateTime) IsZero() bool {
return time.Time(t).IsZero()
}

// IsUnixZerom returns whether the date time is equivalent to time.Unix(0, 0).UTC().
func (t *DateTime) IsUnixZero() bool {
if t == nil {
return true
}
return time.Time(*t).Equal(UnixZero)
func (t DateTime) IsUnixZero() bool {
return time.Time(t) == UnixZero
}

// MarshalText implements the text marshaller interface
Expand Down
12 changes: 3 additions & 9 deletions time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,11 @@ func TestNewDateTime(t *testing.T) {
func TestIsZero(t *testing.T) {
var empty DateTime
assert.True(t, empty.IsZero())
var nilDt *DateTime
assert.True(t, nilDt.IsZero())
small := DateTime(time.Unix(100, 5))
assert.False(t, small.IsZero())
assert.False(t, DateTime(time.Unix(100, 5)).IsZero())

// time.Unix(0,0) does not produce a true zero value struct,
// so this is expected to fail.
dt := NewDateTime()
assert.False(t, dt.IsZero())
assert.False(t, NewDateTime().IsZero())
}

func TestIsUnixZero(t *testing.T) {
Expand All @@ -77,9 +73,7 @@ func TestIsUnixZero(t *testing.T) {
estLocation := time.FixedZone("EST", int((-5 * time.Hour).Seconds()))
estUnixZero := time.Unix(0, 0).In(estLocation)
UnixZero = estUnixZero
t.Cleanup(func() { UnixZero = time.Unix(0, 0).UTC() })
dtz := DateTime(estUnixZero)
assert.True(t, dtz.IsUnixZero())
assert.True(t, DateTime(estUnixZero).IsUnixZero())
}

func TestParseDateTime_errorCases(t *testing.T) {
Expand Down

0 comments on commit 66719db

Please sign in to comment.