StoicBuilder

HandbookI the LudusDates and time zones

Ithe Ludus, Read code

Dates and time zones

1 min readUpdated 28 November

In plain words

A moment in time is best stored in UTC, the world's reference clock, and only turned into local time when it's shown to a person.

Where you see it

A Guildhall event at 8 pm in London shows as 3 pm for a member in New York, which is right. A birthday saved as 5 December shows as 4 December for that same member, which is wrong. Both come from the same step: turning UTC into local time.

src/lib/dates.tsbrowser
// a date-only string is read as midnight UTCconst birthday = new Date("1990-12-05"); // for a visitor in New York, that's the evening beforebirthday.toLocaleDateString("en-US"); // "12/4/1990" // pin the time zone to keep the calendar datebirthday.toLocaleDateString("en-US", { timeZone: "UTC" }); // "12/5/1990"
Same moment, two calendar dates. The time zone decides which one you see.

What goes wrong

  1. Storing a moment without its time zone

    A Postgres timestamp column without time zone drops the offset, so nobody can tell whose 8 pm it was. Use timestamptz for moments in time.

  2. Birthdays that move by a day

    A birthday is a calendar date, not a moment. Store it in a date column and display it without converting, or it slips a day for anyone west of UTC.

  3. Server and browser disagree about today

    Vercel's servers run on UTC while your visitors don't, so "today" can differ for hours. In Next.js this often shows up as a hydration warning.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Store every moment in time as UTC in a timestamptz column and convert to the visitor's time zone only when displaying it. Keep calendar dates like birthdays as plain dates, and show me how an event at 8 pm in London displays for someone in New York.

Quick check

Sign in to earn +10 XP for it

Members west of London see every Guildhall birthday one day early. Most likely cause?

Got a prompt that touches dates and time zones?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.