Skip to content

fix: timezone-aware event time calculation#20

Merged
radiolabme merged 1 commit intomainfrom
fix-issue-12-datetime-calculation
Feb 17, 2026
Merged

fix: timezone-aware event time calculation#20
radiolabme merged 1 commit intomainfrom
fix-issue-12-datetime-calculation

Conversation

@radiolabme
Copy link
Collaborator

Fixes #12

Problem

Events were displaying as "Past Event" before they actually occurred. The January meeting showed as past at 2:18 PM on January 20, even though it was scheduled for 6 PM that day.

Root Cause

The date parsing logic interpreted date-only strings (2026-01-20) as UTC midnight, then applied local timezone conversion. For Pacific time (UTC-8), this shifted the calendar date backward—"January 20 at midnight UTC" became "January 19 at 4 PM Pacific."

Solution

Use the Temporal API (via polyfill) to handle dates correctly:

  1. Extract year/month/day from the date string as calendar values
  2. Use Temporal.PlainDate to represent the calendar date without timezone
  3. Combine with event time in the correct timezone using Temporal.ZonedDateTime
  4. Compare against current time for past/future classification

Changes

  • src/utils/event-time.ts: Added getEventTimestampInTimezone() and isEventPast() functions
  • src/utils/event-time.test.ts: Added 9 tests covering the reported scenario and edge cases
  • src/pages/events/index.astro: Replaced inline date math with utility function imports
  • package.json: Added @js-temporal/polyfill dependency

Testing

All 73 tests pass. The new tests specifically reproduce the reported bug scenario:

  • Event at 6 PM Pacific on 2026-01-20
  • Checked at 2:18 PM Pacific on 2026-01-20
  • Old logic: marked as past (wrong)
  • New logic: marked as upcoming (correct)

Future

When Temporal lands natively in browsers (projected late 2026), the polyfill can be removed without code changes.

Use Temporal polyfill to preserve calendar dates when comparing event
times. JavaScript Date was treating date-only strings as UTC midnight,
causing events to appear as Past before they actually happened.

- Add getEventTimestampInTimezone() using Temporal.PlainDate
- Add isEventPast() for reliable past/future checks
- Update events/index.astro to use new utilities
- Add 9 tests covering timezone edge cases
@radiolabme radiolabme merged commit e448a75 into main Feb 17, 2026
1 check passed
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.

January meeting is shown as 'Past Event' even though it is scheduled for later today

2 participants