Skip to content

Commit

Permalink
Revert "use pointer receivers on the IsZero variants for DateTime"
Browse files Browse the repository at this point in the history
This reverts commit b36a490.

Fixes go-openapi#139

Signed-off-by: Prashant V <[email protected]>
  • Loading branch information
prashantv committed Jan 10, 2025
1 parent 75847d1 commit aaf748e
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 aaf748e

Please sign in to comment.