Fix timezone/DST bugs in event workers using Temporal API#2143
Open
trillium wants to merge 14 commits intodevelopmentfrom
Open
Fix timezone/DST bugs in event workers using Temporal API#2143trillium wants to merge 14 commits intodevelopmentfrom
trillium wants to merge 14 commits intodevelopmentfrom
Conversation
…tle caching, and commit tracking - Python skill (verify_stale_issue.py) with issue type detection - Bash implementations for single and batch issue verification - Label-based scope detection (dev vs non-dev roles) - Title consistency caching system - Git commit history analysis for PR tracking - Decision tree logic for issue verdict categorization
Convert all require() calls for third-party npm packages (express, mongoose, jsonwebtoken, etc.) to ESM import syntax as the first step of the CJS-to-ESM migration.
…ensions Convert all require() calls for relative paths (./x, ../x) to ESM import syntax, adding explicit .js file extensions as required by the ESM module resolution algorithm.
Replace all module.exports assignments with ESM export syntax. Barrel files (models/index.js, controllers/index.js, middleware/index.js, validators/index.js) use named exports; individual modules use export default.
…check Convert the CJS entry-point guard pattern to its ESM equivalent using fileURLToPath(import.meta.url), which is needed because ESM has no require.main.
…configs to .cjs Flip the ESM switch by adding "type": "module" to backend/package.json. Rename jest.config.js and jest-mongodb-config.js to .cjs since Jest config files must remain CommonJS until the Vitest migration.
Replace Jest with Vitest: add vitest.config.js with node environment and 30s timeout, update package.json scripts (test -> vitest run, test:watch -> vitest), convert jest.setup.js to use vi.mock, and remove jest/jest-mongodb config files and dependencies.
… test files Replace all Jest test APIs with their Vitest equivalents (jest.mock -> vi.mock, jest.fn -> vi.fn) and add explicit vitest imports (describe, it, expect, vi, etc.) to every test file.
…-test.js Vitest does not support the done() callback pattern; remove done parameter and done() calls from all test functions, using async/await instead. Add vitest lifecycle imports (beforeAll, afterEach, afterAll) to setup-test.js.
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.
Summary
@js-temporal/polyfillAPIbackend/workers/lib/eventTime.jswith 7 testable, timezone-correct functionsFixes #1872
Background
PR #2079 addressed OOM/batching issues but did not fix the root timezone cause:
getDay(),getHours(),getFullYear(), etc. return values in the server's timezone, not America/Los_Angeles. On a UTC server, a Tuesday 7pm PST event (stored as Wednesday 3am UTC) getsgetDay()=3(Wednesday) andgetHours()=3instead ofgetDay()=2(Tuesday) andgetHours()=19.PR #2116 attempted a fix using
toLocaleStringfake-UTC conversion, but this is a known antipattern that breaks during DST transitions. This PR supersedes that approach.What changed
New file:
backend/workers/lib/eventTime.jsgetEventDayLA(event)— day-of-week in LA time usingTemporal.ZonedDateTimegetTodayDayLA()— today's day-of-week in LA timegenerateEventFromRecurring(filteredEvent, todayDate)— extracts LA time-of-day from stored UTC, combines with today's LA date. DST-safe: 7pm PST stays 7pm PDT after spring-forward.checkIfSameDayLA(eventDate, referenceDate)— same-calendar-day comparison in LA timeisInOpenWindow(eventDate, now)— checkin opens within 30 min (plain ms arithmetic)isPastCloseWindow(eventDate, now)— checkin closes after 3 hours (plain ms arithmetic)Updated workers:
createRecurringEvents.js— usesgetTodayDayLA(),getEventDayLA(),generateEventFromRecurring(),checkIfSameDayLA()openCheckins.js— usesisInOpenWindow()closeCheckins.js— usesisPastCloseWindow()New dependency:
@js-temporal/polyfill— the official TC39 polyfill. Temporal reached Stage 4; when Node ships it natively, the import changes one line.Dependencies
This PR is based on
chore/backend-esm-migration(#2134) and should be merged after #2134 lands.PR #2116 should be closed in favor of this approach.
Test plan
TZ=UTC npx vitest run backend/workers/timezone.test.js— all 8 tests pass