Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates authored Feb 6, 2020
2 parents 47cd4c2 + 35aa903 commit 08354ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions validators/time_after_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ type TimeAfterTime struct {

// IsValid adds an error if the FirstTime is not after the SecondTime.
func (v *TimeAfterTime) IsValid(errors *validate.Errors) {

// UnixNano wraps around to negative numbers when a time is too far
// into the future (e.g. 260 years)
if v.FirstTime.Year() > v.SecondTime.Year() {
return
}

if v.FirstTime.UnixNano() >= v.SecondTime.UnixNano() {
return
}
Expand Down
10 changes: 10 additions & 0 deletions validators/time_after_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ func Test_TimeAfterTime(t *testing.T) {

r.Equal(1, errors.Count())
r.Equal(errors.Get("opens_at"), []string{"OpensAt must be later than Now."})

firstTime := now.AddDate(260, 0, 0)
v = TimeAfterTime{
FirstName: "Opens At", FirstTime: firstTime,
SecondName: "Now", SecondTime: now,
}

errors = validate.NewErrors()
v.IsValid(errors)
r.Equal(0, errors.Count())
}

0 comments on commit 08354ad

Please sign in to comment.