Skip to content

Commit f8e0ca7

Browse files
authored
Merge pull request #4 from quantcli/fix/today-uses-local-timezone
fix: --today uses local calendar date, not UTC
2 parents 7eb37c7 + 1bc46c9 commit f8e0ca7

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

internal/cronoclient/daterange.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import (
1212

1313
const dateLayout = "2006-01-02"
1414

15-
// DateRange is an inclusive [Start, End] window in UTC.
15+
// DateRange is an inclusive [Start, End] window. Only the calendar date
16+
// (YYYY-MM-DD) of each endpoint is sent to Cronometer's export endpoints,
17+
// so the time-of-day and zone on these values don't round-trip — but the
18+
// calendar date is resolved in the user's local zone so that --today
19+
// matches the day the user sees in the Cronometer UI.
1620
type DateRange struct {
1721
Start time.Time
1822
End time.Time
@@ -29,17 +33,18 @@ func AddDateRangeFlags(cmd *cobra.Command) {
2933

3034
// ParseDateRangeFromFlags reads the date-range flags off cmd and resolves
3135
// them into a concrete DateRange. Default when no flags are passed: the
32-
// last 7 days ending today (UTC).
36+
// last 7 days ending today. "Today" is the user's local calendar day.
3337
func ParseDateRangeFromFlags(cmd *cobra.Command) (DateRange, error) {
3438
startStr, _ := cmd.Flags().GetString("start")
3539
endStr, _ := cmd.Flags().GetString("end")
3640
days, _ := cmd.Flags().GetInt("days")
3741
today, _ := cmd.Flags().GetBool("today")
38-
return resolveDateRange(startStr, endStr, days, today, time.Now().UTC())
42+
return resolveDateRange(startStr, endStr, days, today, time.Now())
3943
}
4044

4145
func resolveDateRange(startStr, endStr string, days int, today bool, ref time.Time) (DateRange, error) {
42-
now := ref.Truncate(24 * time.Hour)
46+
y, m, d := ref.Date()
47+
now := time.Date(y, m, d, 0, 0, 0, 0, ref.Location())
4348
var start, end time.Time
4449

4550
switch {

0 commit comments

Comments
 (0)