Skip to content

Commit 66719db

Browse files
authored
Merge pull request #140 from prashantv/iszero
Revert "use pointer receivers on the IsZero variants for DateTime"
2 parents 75847d1 + aaf748e commit 66719db

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

time.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,13 @@ func (t DateTime) String() string {
135135
}
136136

137137
// IsZero returns whether the date time is a zero value
138-
func (t *DateTime) IsZero() bool {
139-
if t == nil {
140-
return true
141-
}
142-
return time.Time(*t).IsZero()
138+
func (t DateTime) IsZero() bool {
139+
return time.Time(t).IsZero()
143140
}
144141

145142
// IsUnixZerom returns whether the date time is equivalent to time.Unix(0, 0).UTC().
146-
func (t *DateTime) IsUnixZero() bool {
147-
if t == nil {
148-
return true
149-
}
150-
return time.Time(*t).Equal(UnixZero)
143+
func (t DateTime) IsUnixZero() bool {
144+
return time.Time(t) == UnixZero
151145
}
152146

153147
// MarshalText implements the text marshaller interface

time_test.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,11 @@ func TestNewDateTime(t *testing.T) {
5858
func TestIsZero(t *testing.T) {
5959
var empty DateTime
6060
assert.True(t, empty.IsZero())
61-
var nilDt *DateTime
62-
assert.True(t, nilDt.IsZero())
63-
small := DateTime(time.Unix(100, 5))
64-
assert.False(t, small.IsZero())
61+
assert.False(t, DateTime(time.Unix(100, 5)).IsZero())
6562

6663
// time.Unix(0,0) does not produce a true zero value struct,
6764
// so this is expected to fail.
68-
dt := NewDateTime()
69-
assert.False(t, dt.IsZero())
65+
assert.False(t, NewDateTime().IsZero())
7066
}
7167

7268
func TestIsUnixZero(t *testing.T) {
@@ -77,9 +73,7 @@ func TestIsUnixZero(t *testing.T) {
7773
estLocation := time.FixedZone("EST", int((-5 * time.Hour).Seconds()))
7874
estUnixZero := time.Unix(0, 0).In(estLocation)
7975
UnixZero = estUnixZero
80-
t.Cleanup(func() { UnixZero = time.Unix(0, 0).UTC() })
81-
dtz := DateTime(estUnixZero)
82-
assert.True(t, dtz.IsUnixZero())
76+
assert.True(t, DateTime(estUnixZero).IsUnixZero())
8377
}
8478

8579
func TestParseDateTime_errorCases(t *testing.T) {

0 commit comments

Comments
 (0)