Skip to content

Commit

Permalink
Use Equal from time.Time for equality checks.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 590650143
  • Loading branch information
ItsMattL authored and copybara-github committed Dec 13, 2023
1 parent cf11cf5 commit 6a3813b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions window/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (w *Window) NextActivation(ts time.Time) time.Time {
// Activation time search timeout
for time.Since(start) < (5 * time.Second) {
b := w.Cron.Next(a.Add(-2 * time.Second))
if a == b {
if a.Equal(b) {
return b
}
a = b
Expand All @@ -345,7 +345,7 @@ func (w *Window) LastActivation(date time.Time) time.Time {
// catch schedules of all frequencies. Omitting the first number in
// sequence (0) as it provides no value, only computational cost.
fibCurrent, fibLast := 1, 1
for next == last {
for next.Equal(last) {
fibCurrent, fibLast = fibLast, fibCurrent+fibLast
last = w.NextActivation(date.Add(-time.Duration(fibCurrent) * time.Minute))
}
Expand Down Expand Up @@ -421,7 +421,7 @@ func (s *Schedule) Overlaps(c Schedule) bool {
return true
}
// s and c match
if c.Opens == s.Opens && c.Closes == s.Closes {
if c.Opens.Equal(s.Opens) && c.Closes.Equal(s.Closes) {
return true
}
return false
Expand Down
12 changes: 6 additions & 6 deletions window/window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@ func TestCalculateSchedule(t *testing.T) {
)
t.Errorf("TestCalculateSchedule(%q) duration:: got: %s; want: %s", e.windowName, gotDur, expectDur)
}
if got.Opens != e.expect.Opens {
if !got.Opens.Equal(e.expect.Opens) {
t.Errorf("TestCalculateSchedule(%q) opens:: got: %s; want: %s", e.windowName, got.Opens, e.expect.Opens)
}
if got.Closes != e.expect.Closes {
if !got.Closes.Equal(e.expect.Closes) {
t.Errorf("TestCalculateSchedule(%q) closes:: got: %s; want: %s", e.windowName, got.Closes, e.expect.Closes)
}
}
Expand Down Expand Up @@ -613,7 +613,7 @@ func TestWindowActivation(t *testing.T) {

w := Window{Format: 1, Cron: cr}
last := w.LastActivation(a.time)
if last != a.last {
if !last.Equal(a.last) {
t.Errorf("TestActivation(%q) last activation: got: %s; want: %s", a.desc, last, a.last)
}

Expand All @@ -622,7 +622,7 @@ func TestWindowActivation(t *testing.T) {
t.Errorf("TestActivation(%q) next activation search timeout exceeded.", a.desc)
}

if next != a.next {
if !next.Equal(a.next) {
t.Errorf("TestActivation(%q) next activation: got: %s; want: %s", a.desc, next, a.next)
}
}
Expand Down Expand Up @@ -726,10 +726,10 @@ func TestScheduleCombine(t *testing.T) {
if err != nil && e.overlaps {
t.Errorf("TestScheduleCombine(%q) error: %v", e.desc, err)
}
if e.base.Opens != e.combined.Opens {
if !e.base.Opens.Equal(e.combined.Opens) {
t.Errorf("TestScheduleCombine(%q) incorrect opening time. got: %s; want: %s", e.desc, e.base.Opens, e.combined.Opens)
}
if e.base.Closes != e.combined.Closes {
if !e.base.Closes.Equal(e.combined.Closes) {
t.Errorf("TestScheduleCombine(%q) incorrect closing time. got: %s; want: %s", e.desc, e.base.Closes, e.combined.Closes)
}
dur := e.combined.Closes.Sub(e.combined.Opens)
Expand Down

0 comments on commit 6a3813b

Please sign in to comment.