From 6a3813b117743a1407076b04ea70d0617ed81385 Mon Sep 17 00:00:00 2001 From: Matt LaPlante Date: Wed, 13 Dec 2023 10:50:57 -0800 Subject: [PATCH] Use Equal from time.Time for equality checks. PiperOrigin-RevId: 590650143 --- window/window.go | 6 +++--- window/window_test.go | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/window/window.go b/window/window.go index cd5fc3e..b939de1 100644 --- a/window/window.go +++ b/window/window.go @@ -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 @@ -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)) } @@ -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 diff --git a/window/window_test.go b/window/window_test.go index d687385..d11acd1 100644 --- a/window/window_test.go +++ b/window/window_test.go @@ -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) } } @@ -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) } @@ -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) } } @@ -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)