Skip to content

fix: timezone-aware contest scheduling and display - #94

Merged
JustModo merged 3 commits into
masterfrom
feat/timezone-handling
Jun 6, 2026
Merged

fix: timezone-aware contest scheduling and display#94
JustModo merged 3 commits into
masterfrom
feat/timezone-handling

Conversation

@Rajaykumar12

@Rajaykumar12 Rajaykumar12 commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Root cause fixed: The "Ends At" time was parsed via setHours() inside a Next.js Server Action (which runs in UTC), so an admin in IST entering "01:30 PM" would store 13:30 UTC instead of 08:00 UTC (the correct equivalent)
  • End time now computed in the browser: info-card.tsx derives endsAt as a UTC ISO string using the browser's local timezone, consistent with how startsAt was already handled; the server action receives two UTC ISO strings and does no timezone math
  • Edit form fixed: When editing a contest, the stored UTC endTime is converted back to the admin's local time display via the browser's Intl API, not the server's clock
  • All time displays updated: Every timestamp across the app now uses toLocaleString with timeZoneName: 'short' so each viewer sees times in their own local timezone with the abbreviation (e.g. "10:00 AM IST" for India, "4:30 AM UTC" for a UTC viewer)
  • New <LocalTime> client component: Used in server-rendered pages (result, submissions) where timezone conversion must happen on the client after hydration
  • Timezone label in admin form: Shows the admin's detected timezone (e.g. Asia/Kolkata) so they know how their inputs are interpreted

Test plan

  • Create a new contest as admin — verify start/end times stored in MongoDB are correct UTC equivalents of the local input
  • Edit an existing contest — verify "Ends At" field shows the correct local time (not UTC)
  • View the test landing page from a different timezone (DevTools → Sensors → Location) — verify times convert correctly with timezone abbreviation
  • Check admin test list, test detail card, leaderboard, and submissions pages all show local time with abbreviation

Add endsAt as a required UTC ISO datetime field in the zod testSchema
so the end time is validated as a proper timestamp rather than a
locale-dependent time string. Also expose endsAt as an optional field
on the Test interface for edit-form population.
…imezone

Previously, the "Ends At" time string was parsed and applied via
setHours() inside a Next.js Server Action (UTC on server), so an admin
in IST entering "01:30 PM" would store 13:30 UTC instead of 08:00 UTC.

Fix by computing endsAt as a UTC ISO string entirely in the browser
(info-card.tsx), consistent with how startsAt is already handled.
The server action now receives and validates two UTC ISO strings
directly, with no timezone-sensitive arithmetic.

On edit, the stored UTC endsAt is converted back to the admin's local
time display using the browser's Intl API.
…breviation

Replace date-fns format() calls with toLocaleString/toLocaleTimeString
using timeZoneName:'short', so every displayed timestamp automatically
converts the stored UTC value to the viewer's browser timezone and
shows the abbreviation (e.g. "10:00 AM IST", "4:30 AM UTC").

Add a LocalTime client component for server-rendered pages (result,
submissions) where timezone conversion must happen on the client.

Also show the admin's local timezone name in the test creation form
so they know which timezone their inputs are interpreted in.
@Rajaykumar12
Rajaykumar12 force-pushed the feat/timezone-handling branch from f12605f to 84a7808 Compare June 6, 2026 10:19
@Rajaykumar12
Rajaykumar12 requested a review from Copilot June 6, 2026 14:44
@Rajaykumar12
Rajaykumar12 requested review from JustModo and removed request for Copilot June 6, 2026 14:44

@JustModo JustModo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Good, thanks!

@JustModo
JustModo merged commit 16abdd4 into master Jun 6, 2026
1 check passed
@JustModo
JustModo deleted the feat/timezone-handling branch June 6, 2026 15:31
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.

2 participants