fix potential endless loop during queue msg/hook pagination when environment has TZ UTC, triggered by tests introduced in previous test

time.Now() returns a timestamp with timezone Local. if you marshal & unmarshal
it again, it'll get the Local timezone again. unless the local timezone is UTC.
then it will get the UTC timezone. the same time.Time but with explicit UTC
timezone vs explicit UTC-as-Local timezone are not the same when comparing with
==. so comparison should be done with time.Time.Equal, or comparison should be
done after having called .Local() on parsed timestamps (so the explicit UTC
timezone gets converted to the UTC-as-Local timezone). somewhat surprising that
time.Local isn't the same as time.UTC if TZ=/TZ=UTC. there are warnings
throughout the time package about handling of UTC.
This commit is contained in:
Mechiel Lukkien
2024-04-16 13:58:08 +02:00
parent 09fcc49223
commit daa88480cb
4 changed files with 10 additions and 9 deletions

View File

@ -313,9 +313,9 @@ func (s HookSort) apply(q *bstore.Query[Hook]) error {
q.FilterNotEqual("ID", s.LastID)
var fieldEqual func(h Hook) bool
if s.Field == "NextAttempt" {
fieldEqual = func(h Hook) bool { return h.NextAttempt == last }
fieldEqual = func(h Hook) bool { return h.NextAttempt.Equal(last) }
} else {
fieldEqual = func(h Hook) bool { return h.Submitted == last }
fieldEqual = func(h Hook) bool { return h.Submitted.Equal(last) }
}
if s.Asc {
q.FilterGreaterEqual(s.Field, last)
@ -454,9 +454,9 @@ func (s HookRetiredSort) apply(q *bstore.Query[HookRetired]) error {
q.FilterNotEqual("ID", s.LastID)
var fieldEqual func(hr HookRetired) bool
if s.Field == "LastActivity" {
fieldEqual = func(hr HookRetired) bool { return hr.LastActivity == last }
fieldEqual = func(hr HookRetired) bool { return hr.LastActivity.Equal(last) }
} else {
fieldEqual = func(hr HookRetired) bool { return hr.Submitted == last }
fieldEqual = func(hr HookRetired) bool { return hr.Submitted.Equal(last) }
}
if s.Asc {
q.FilterGreaterEqual(s.Field, last)