From 569859d7cdcf0cc52b9bd3e8e20ed549ce8ef4c9 Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Sun, 21 Mar 2021 12:13:42 +0100 Subject: [PATCH] fix(tz): compare datetimes using timezones Signed-off-by: Felipe Zipitria --- main.go | 3 ++- waflog/read.go | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index ec585c5c..12b3f6cb 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,8 @@ func main() { zerolog.SetGlobalLevel(zerolog.InfoLevel) // Load timezone location based on TZ - loc, err := time.LoadLocation(os.Getenv("TZ")) + tzone, _ := time.Now().Zone() + loc, err := time.LoadLocation(tzone) if err != nil { log.Error().Msgf("ftw/main: cannot load timezone") } else { diff --git a/waflog/read.go b/waflog/read.go index 3fbd1d7e..15c23341 100644 --- a/waflog/read.go +++ b/waflog/read.go @@ -100,10 +100,12 @@ func (ll *FTWLogLines) getLinesSinceUntil() [][]byte { break } // compare dates now + // use the same timezone for all + dt := t.InTimezone(gostradamus.Local()) since := gostradamus.DateTimeFromTime(ll.Since).InTimezone(gostradamus.Local()) until := gostradamus.DateTimeFromTime(ll.Until).InTimezone(gostradamus.Local()) // Comparision will need to truncate - if isBetweenOrEqual(t, since, until, ll.TimeTruncate) { + if isBetweenOrEqual(dt, since, until, ll.TimeTruncate) { saneCopy := make([]byte, len(line)) copy(saneCopy, line) found = append(found, saneCopy) @@ -114,7 +116,7 @@ func (ll *FTWLogLines) getLinesSinceUntil() [][]byte { until.Format(ll.TimeFormat)) } // if we are before since, we need to stop searching - if t.IsBetween(gostradamus.DateTimeFromTime(time.Time{}).InTimezone(gostradamus.Local()), + if dt.IsBetween(gostradamus.DateTimeFromTime(time.Time{}).InTimezone(gostradamus.Local()), since) { break }