Skip to content

Commit

Permalink
Merge pull request #22 from fzipi/compare-with-timezones
Browse files Browse the repository at this point in the history
fix(tz): compare datetimes using timezones
  • Loading branch information
fzipi authored Mar 21, 2021
2 parents 5177c1b + 569859d commit af56f06
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions waflog/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down

0 comments on commit af56f06

Please sign in to comment.