Skip to content

fix: parse --start/--end in local time#5

Merged
DTTerastar merged 1 commit into
mainfrom
fix/timezone-local
Apr 22, 2026
Merged

fix: parse --start/--end in local time#5
DTTerastar merged 1 commit into
mainfrom
fix/timezone-local

Conversation

@DTTerastar
Copy link
Copy Markdown
Collaborator

Summary

  • Swap time.ParseInLocation(..., time.UTC)time.ParseInLocation(..., ref.Location()) in resolveDateRange, so absolute --start / --end flags resolve to the user's local midnight.
  • Matches the behavior --today already had (line 47 already used ref.Location()) and the explicit promise in the package docstring.

Before, a user in EDT running `--start 2025-01-01` asked Cronometer for the window starting at 2024-12-31 20:00 local — silently off by a day.

Test plan

  • `go build ./...` passes
  • `crono-export servings --today` returns today's records
  • Reviewer: verify `--start YYYY-MM-DD` now matches what you'd see in the Cronometer web UI for that date

🤖 Generated with Claude Code

Previously, time.ParseInLocation(..., time.UTC) meant --start 2025-01-01
resolved to UTC midnight — which in EDT is Dec 31 at 8pm local. The API
received the wrong calendar boundary, silently shifting results by one
day for users west of UTC.

Parse with ref.Location() so absolute dates match the user's local
calendar, consistent with --today (which was already local) and with the
package docstring's explicit promise.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@DTTerastar DTTerastar merged commit 1a71028 into main Apr 22, 2026
1 check passed
DTTerastar added a commit that referenced this pull request May 19, 2026
Review feedback on #44:

- **Must fix #1: README.md stale.** Replaced the "no token cache"
  paragraph with the cache location ($XDG_CACHE_HOME), the
  CRONOMETER_NO_CACHE opt-out, the `auth logout` subcommand, and a
  security note ("treat session.json like a password").  Folds in the
  reviewer's nice-to-have #5 (security guidance) at the same time.

- **Must fix #2: gofmt.**  Ran `gofmt -w` on `cmd/format.go` and
  `internal/cronoclient/daterange_test.go` (trailing blank line + struct
  field alignment).  `internal/cronoapi/gwt.go` is also flagged but is
  pre-existing from #37 — landed as a separate chore commit so this
  PR's diff stays scoped to release-blocker work.

- **Nice-to-have #4: cache schema version.**  Added
  `cacheSchemaVersion = 1` and a `Version int` field on cachedSession.
  Old/mismatched versions are silently treated as a miss so a future
  incompatible bump triggers a transparent re-login instead of a
  JSON-shape error.  New test: TestSessionCacheVersionMismatch.

Skipped: race on concurrent fresh logins (#6) — reviewer agreed this is
fine for a single-user CLI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
DTTerastar added a commit that referenced this pull request May 19, 2026
* feat: release-blocker bundle for v0.2.0 (#17 #18 #21 #16 #15 #23 #39 #40)

Bundles eight ship-blocker fixes called out in the QA triage on main:

- **#39 session cache (major):** persist auth/cookies to
  $XDG_CACHE_HOME/crono-export/session.json (mode 0600), retry-on-stale,
  CRONOMETER_NO_CACHE escape hatch, new `auth logout` subcommand. Fixes
  the rate-limit foot-gun where 5–6 back-to-back calls trip Cronometer's
  throttle. Also de-duplicates the "login failed: login failed:" wrap.
- **#17 typed nutrition/notes JSON (breaking):** csvToJSON now returns
  []map[string]any with best-effort coercion (numeric → float64,
  true/false → bool, empty → null). Drops the contract drift where two
  of five subcommands forced jq `tonumber` on every column.
- **#15 + #23 validation before login:** Args=cobra.NoArgs + a PreRunE
  that calls chosenFormat — bad --format / positional args now exit
  fast without burning a Cronometer login attempt.
- **#16 + #18 + #21 contract-violation trio:** empty markdown is silent
  on stdout (friendly note → stderr); --until alone uses 7d window
  ending at --until (was 1-day); inverted --since/--until warns to
  stderr and returns empty + exit 0 (was non-zero error).
- **#40 VitaminDIU cosmetic:** strippedSuffix table had "UI" instead of
  the standard "IU" abbreviation; vitamin D markdown was rendering
  without splitting the unit. Added TestStrippedSuffix to cover.
- **#19 closed as part-fixed/part-wontfix:** zone-as-UTC was already
  fixed by the clean-room rewrite (#37); the wire CSV carries no
  time-of-day to surface. Documented in prime GOTCHAS.

New tests cover: strippedSuffix (cmd), resolveDateRange (cronoclient),
coerceCSVValue + csvToJSON (cronoclient), session cache round-trip
(cronoclient).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fixup: address PR review — README, gofmt, cache schema version

Review feedback on #44:

- **Must fix #1: README.md stale.** Replaced the "no token cache"
  paragraph with the cache location ($XDG_CACHE_HOME), the
  CRONOMETER_NO_CACHE opt-out, the `auth logout` subcommand, and a
  security note ("treat session.json like a password").  Folds in the
  reviewer's nice-to-have #5 (security guidance) at the same time.

- **Must fix #2: gofmt.**  Ran `gofmt -w` on `cmd/format.go` and
  `internal/cronoclient/daterange_test.go` (trailing blank line + struct
  field alignment).  `internal/cronoapi/gwt.go` is also flagged but is
  pre-existing from #37 — landed as a separate chore commit so this
  PR's diff stays scoped to release-blocker work.

- **Nice-to-have #4: cache schema version.**  Added
  `cacheSchemaVersion = 1` and a `Version int` field on cachedSession.
  Old/mismatched versions are silently treated as a miss so a future
  incompatible bump triggers a transparent re-login instead of a
  JSON-shape error.  New test: TestSessionCacheVersionMismatch.

Skipped: race on concurrent fresh logins (#6) — reviewer agreed this is
fine for a single-user CLI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* chore: gofmt internal/cronoapi/gwt.go (preexisting drift from #37)

Pure formatting: column-aligned const block and var block. No logic change.
Flagged by `gofmt -l .` during review of #44.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@DTTerastar DTTerastar deleted the fix/timezone-local branch May 19, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant