Skip to content

Commit

Permalink
Merge pull request #7 from anihex/master
Browse files Browse the repository at this point in the history
Added IsZero for null.Time
  • Loading branch information
nullbio authored Jan 25, 2019
2 parents 3ca3c13 + bb3f3fd commit 3050386
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions time.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func (t Time) Ptr() *time.Time {
return &t.Time
}

// IsZero returns true for an invalid Time's value, for potential future omitempty support.
func (t Time) IsZero() bool {
return !t.Valid
}

// Scan implements the Scanner interface.
func (t *Time) Scan(value interface{}) error {
var err error
Expand Down
12 changes: 12 additions & 0 deletions time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ func TestTimePointer(t *testing.T) {
}
}

func TestTimeIsZero(t *testing.T) {
ti := TimeFrom(time.Now())
if ti.IsZero() {
t.Errorf("IsZero() should be false")
}

null := TimeFromPtr(nil)
if !null.IsZero() {
t.Errorf("IsZero() should be true")
}
}

func TestTimeScanValue(t *testing.T) {
var ti Time
err := ti.Scan(timeValue)
Expand Down

0 comments on commit 3050386

Please sign in to comment.