Skip to content

fix: pass time.Local to gocronometer parsers — closes #13#28

Merged
DTTerastar merged 1 commit into
mainfrom
fix/timestamps-in-local-zone
May 9, 2026
Merged

fix: pass time.Local to gocronometer parsers — closes #13#28
DTTerastar merged 1 commit into
mainfrom
fix/timestamps-in-local-zone

Conversation

@DTTerastar

@DTTerastar DTTerastar commented May 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #13. Three call sites in `cronoclient.Client` hardcoded `time.UTC` when invoking `ExportServingsParsedWithLocation`, `ExportExercisesParsedWithLocation`, and `ExportBiometricRecordsParsedWithLocation`. The result was every `RecordedTime` emitted by these subcommands carried a UTC offset (`...Z`) regardless of the host zone, in direct violation of CONTRACT §2.

Beyond the JSON cosmetic, this caused the markdown date-bucketing in `cmd/format.go` (`r.RecordedTime.Format("2006-01-02")`) to compute the wrong calendar day for any host west of UTC: a record logged at 9pm local on day N bucketed one day late.

```diff

  • recs, err := c.inner.ExportServingsParsedWithLocation(ctx, rng.Start, rng.End, time.UTC)
  • recs, err := c.inner.ExportServingsParsedWithLocation(ctx, rng.Start, rng.End, time.Local)
    ```

(× 3, all in `internal/cronoclient/client.go`.)

Test plan

  • `go build ./...`, `go vet ./...` pass
  • Before:
    ```
    $ crono-export servings --since 7d --format json | jq '.[0].RecordedTime'
    "2026-05-02T00:00:00Z"
    ```
  • After:
    ```
    $ crono-export servings --since 7d --format json | jq '.[0].RecordedTime'
    "2026-05-02T00:00:00-04:00"
    ```
  • Reviewer: confirm markdown date headings (`## 2026-05-02`) match the date you see in the Cronometer web UI for late-evening records

🤖 Generated with Claude Code

Made with Orca 🐋

Three call sites in cronoclient.Client hardcoded time.UTC when invoking
ExportServingsParsedWithLocation, ExportExercisesParsedWithLocation, and
ExportBiometricRecordsParsedWithLocation. The result was that every
RecordedTime emitted by these subcommands carried a UTC offset (`...Z`)
regardless of the host zone, in direct violation of the timezone
contract: https://github.com/quantcli/common/blob/main/CONTRACT.md#2-timezone-policy

Beyond the JSON cosmetic, this caused the markdown date-bucketing in
cmd/format.go (`r.RecordedTime.Format("2006-01-02")`) to compute the
wrong calendar day for any host west of UTC: a record logged at 9pm
local on day N bucketed one day late.

Fix: time.UTC → time.Local in all three calls.

Verified:
  $ crono-export servings --since 7d --format json | jq '.[0].RecordedTime'
  "2026-05-02T00:00:00-04:00"   # was "2026-05-02T00:00:00Z"

Closes #13.

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

Co-authored-by: Orca <help@stably.ai>
@DTTerastar
DTTerastar merged commit f6e8f1f into main May 9, 2026
1 check passed
@DTTerastar
DTTerastar deleted the fix/timestamps-in-local-zone branch May 9, 2026 15:18
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.

API timestamps emitted in UTC, not the user's local zone — violates timezone contract

1 participant