Skip to content

Commit 1bc46c9

Browse files
DTTerastarclaude
andcommitted
fix: resolve --today against local calendar date
--today, --days N, and the default 7-day window previously used time.Now().UTC(), so in timezones west of UTC, "today" flipped to the next day shortly after local evening. At 20:xx ET (~00:xx UTC next day), `crono-export nutrition --today` queried tomorrow's UTC date and returned an empty result even though the user had logged food "today". Resolve the reference day from the user's local zone instead, and construct midnight with time.Date rather than Truncate(24*time.Hour) (which only aligns to midnight in UTC). Explicit --start/--end string parsing is unchanged; the fix only affects the three relative modes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7eb37c7 commit 1bc46c9

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)