Fix business date rollover and make timezone a setting - #8
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The date field on
/calculatewas computed withnew 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 showed7/14/26while it was still7/13/26in Pacific.Two things also needed fixing beyond raw timezone:
Changes
$lib/business-date.ts— new pure helpers:businessDate(now, timeZone, rolloverHour = 3)→YYYY-MM-DDfor 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'.America/Los_Angeles): seeded indb.ts, validated + persisted insettings/+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.tsuses 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./calculatenow 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