Skip to content

Fix business date rollover and make timezone a setting - #8

Merged
bradydibble merged 1 commit into
mainfrom
claude/pacific-timezone-setting
Jul 14, 2026
Merged

Fix business date rollover and make timezone a setting#8
bradydibble merged 1 commit into
mainfrom
claude/pacific-timezone-setting

Conversation

@bradydibble

Copy link
Copy Markdown
Owner

Problem

The date field on /calculate was computed with new Date().toISOString() — i.e. in UTC. After ~5 PM Pacific (when UTC crosses midnight) the form defaulted to tomorrow's date. This is the reported bug: the site showed 7/14/26 while it was still 7/13/26 in Pacific.

Two things also needed fixing beyond raw timezone:

  • The timezone was hardcoded — it's now a setting.
  • A restaurant's business day shouldn't roll to the next date at midnight. Late-night close-outs belong to the day the shift started, so the date should not advance until after 3 AM local time.

Changes

  • $lib/business-date.ts — new pure helpers:
    • businessDate(now, timeZone, rolloverHour = 3)YYYY-MM-DD for the configured timezone, staying on the prior day until 3 AM local.
    • defaultShift(...) → Lunch/Dinner default; the post-midnight close-out window now defaults to Dinner.
    • isValidTimeZone(...), DEFAULT_TIMEZONE = 'America/Los_Angeles'.
  • Timezone is now a setting (default America/Los_Angeles): seeded in db.ts, validated + persisted in settings/+page.server.ts, and selectable via a dropdown of common US zones in the Settings UI. The "Lunch Cutoff" label is no longer hardcoded to "Pacific".
  • calculate/+page.server.ts uses the helpers with the configured timezone instead of UTC.
  • business-date.test.ts — 19 tests: the reported bug, the 3 AM boundary (2:59 vs 3:00), closing time (1 AM stays prior day), month/year boundaries, spring-forward DST, and an alternate timezone.

Verification

  • npm test (44 tests), npm run check (0 errors), npm run lint — all green.
  • Drove the real app against the live clock (9 PM Pacific / next-day UTC): /calculate now defaults to the correct Pacific date, and switching the timezone setting to UTC flips it (proving the setting drives the computation), switching back restores it. Invalid timezones are rejected.

🤖 Generated with Claude Code

The date field on /calculate was computed with `new Date().toISOString()`,
i.e. in UTC, so after ~5 PM Pacific it jumped to tomorrow's date. Restaurant
close-outs after midnight also need to stay on the day the shift started.

- Add $lib/business-date.ts: businessDate() and defaultShift() reason in a
  configurable IANA timezone and roll the business day over at 3 AM local
  time, so late-night entries stay on the prior date until after 3 AM.
- Make timezone a setting (default America/Los_Angeles): seeded in db.ts,
  validated + persisted in settings, and selectable via a dropdown of common
  US zones in the Settings UI.
- Use businessDate()/defaultShift() in the calculate load with the configured
  timezone. defaultShift now treats the post-midnight close-out window as
  Dinner.
- Add business-date.test.ts covering the reported bug, the 3 AM boundary,
  closing time, month/year boundaries, DST, and alternate timezones.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bradydibble
bradydibble merged commit db5dbf7 into main Jul 14, 2026
1 check passed
@bradydibble
bradydibble deleted the claude/pacific-timezone-setting branch July 14, 2026 04:22
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