Skip to content

Commit

Permalink
fix: use system timezone
Browse files Browse the repository at this point in the history
Incorrect bucket values were observed on timeseries endpoint. This commit
ensures all timeutil functions uses provided system timezone.
  • Loading branch information
gernest committed Mar 20, 2024
1 parent 69363a3 commit 17f1891
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/compute/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Realtime(ctx context.Context, scan db.Scanner, req *v1.Realtime_Request) (*
if err != nil {
return nil, err
}
now := time.Now().UTC()
now := time.Now()
firstTime := now.Add(-5 * time.Minute)
result, err := scan.Scan(ctx,
firstTime.UnixMilli(),
Expand Down
14 changes: 7 additions & 7 deletions internal/timeutil/timeutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package timeutil
import "time"

func Today() time.Time {
return BeginDay(time.Now().UTC())
return BeginDay(time.Now())
}

func beginMinute(ts time.Time) time.Time {
Expand All @@ -12,17 +12,17 @@ func beginMinute(ts time.Time) time.Time {

func beginHour(ts time.Time) time.Time {
y, m, d := ts.Date()
return time.Date(y, m, d, ts.Hour(), 0, 0, 0, time.UTC)
return time.Date(y, m, d, ts.Hour(), 0, 0, 0, ts.Location())
}

func BeginDay(ts time.Time) time.Time {
yy, mm, dd := ts.Date()
return time.Date(yy, mm, dd, 0, 0, 0, 0, time.UTC)
return time.Date(yy, mm, dd, 0, 0, 0, 0, ts.Location())
}

func Day(ts time.Time, dd int) time.Time {
yy, mm, _ := ts.Date()
return time.Date(yy, mm, dd, 0, 0, 0, 0, time.UTC)
return time.Date(yy, mm, dd, 0, 0, 0, 0, ts.Location())
}

func BeginWeek(ts time.Time) time.Time {
Expand All @@ -32,7 +32,7 @@ func BeginWeek(ts time.Time) time.Time {

func BeginMonth(ts time.Time) time.Time {
yy, mm, _ := ts.Date()
return time.Date(yy, mm, 1, 0, 0, 0, 0, time.UTC)
return time.Date(yy, mm, 1, 0, 0, 0, 0, ts.Location())
}

func EndOfHour(ts time.Time) time.Time {
Expand All @@ -45,7 +45,7 @@ func EndOfMinute(ts time.Time) time.Time {

func EndDay(ts time.Time) time.Time {
yy, mm, dd := ts.Date()
return time.Date(yy, mm, dd, 23, 59, 59, int(time.Second-time.Nanosecond), time.UTC)
return time.Date(yy, mm, dd, 23, 59, 59, int(time.Second-time.Nanosecond), ts.Location())
}

func EndWeek(ts time.Time) time.Time {
Expand All @@ -58,7 +58,7 @@ func EndMonth(ts time.Time) time.Time {

func BeginYear(ts time.Time) time.Time {
yy, _, _ := ts.Date()
return time.Date(yy, time.January, 1, 0, 0, 0, 0, time.UTC)
return time.Date(yy, time.January, 1, 0, 0, 0, 0, ts.Location())
}

func EndYear(ts time.Time) time.Time {
Expand Down

0 comments on commit 17f1891

Please sign in to comment.