Skip to content

feat: add timezone selector and fix timezone conversion bug#127

Open
webtaken wants to merge 1 commit intocrafter-station:mainfrom
webtaken:webtaken/timezone-selector-fix
Open

feat: add timezone selector and fix timezone conversion bug#127
webtaken wants to merge 1 commit intocrafter-station:mainfrom
webtaken:webtaken/timezone-selector-fix

Conversation

@webtaken
Copy link
Copy Markdown
Collaborator

Summary

  • Add a LATAM timezone selector (19 timezones) to the event creation/edit form using SearchableSelect
  • Fix bug where event dates were stored with wrong UTC offset due to timezone-unaware parsing

Bug Details

When creating an event with a non-default timezone, dates were stored incorrectly. The form sent bare datetime strings (e.g. 2026-03-28T22:45) which new Date() parsed in the server's local timezone instead of the event's selected timezone.

Example: Creating an event at 10:45 PM Buenos Aires (ART, UTC-3):

  • Expected in DB: 2026-03-29T01:45:00Z (22:45 + 3h)
  • Actual in DB: 2026-03-29T03:45:00Z (parsed as server timezone UTC-5 instead)

This caused the detail page to show "domingo 29 de marzo, 12:45 AM (ART)" instead of the correct "sábado 28 de marzo, 10:45 PM (ART)", and the countdown to display ~4h 52m instead of ~2h 52m.

Fix

Use fromZonedTime() from date-fns-tz to properly convert local event times to UTC before storage, in both createEvent and updateEvent flows.

Files Changed

  • lib/event-utils.ts — Export TIMEZONE_ABBRS at module level, add TIMEZONE_OPTIONS
  • lib/actions/events.ts — Use fromZonedTime() for date conversion in createEvent
  • components/org/creation/org-event-form-minimal.tsx — Add timezone selector, use fromZonedTime() in edit mode

Test plan

  • Create event with Buenos Aires timezone at a specific time, verify DB stores correct UTC
  • Verify detail page shows the time in the event's timezone with correct label (ART)
  • Verify countdown shows correct time remaining relative to viewer's local time
  • Edit an existing event, verify timezone pre-populates correctly
  • bun run build passes

🤖 Generated with Claude Code

Add a LATAM timezone selector to the event creation/edit form using
SearchableSelect with searchable dropdown (19 LATAM timezones).

Fix bug where event dates were incorrectly stored in UTC. The form sent
bare datetime strings (e.g. "2026-03-28T22:45") which were parsed via
new Date() in the server's local timezone instead of the event's
selected timezone. For example, creating an event at 10:45 PM in Buenos
Aires (ART, UTC-3) should be stored as 2026-03-29T01:45:00Z, but was
stored as 2026-03-29T03:45:00Z because the server interpreted the time
in its own timezone (UTC-5). This caused the detail page to display
"domingo 29 de marzo, 12:45 AM (ART)" instead of the correct "sábado
28 de marzo, 10:45 PM (ART)", and the countdown to show ~4h 52m
instead of ~2h 52m.

Fixed by using fromZonedTime() from date-fns-tz to properly convert
local event times to UTC before storage, in both createEvent and
updateEvent flows.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 29, 2026

@webtaken is attempting to deploy a commit to the Crafter Station Team on Vercel.

A member of the Team first needs to authorize it.

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