Writing
Fullstack English

Timezone Bugs: Store UTC, Display Local, Stop Guessing

Why orders made at 23:30 WIB show up 'yesterday', and the discipline that ends the whole bug class - including the DST trap Indonesia lulls you into.

  • Published
  • 1 min read

The bug report says: “order placed last night shows the wrong date.” The cause is always the same - somewhere, a naive datetime crossed a layer without its timezone, and every layer after it guessed.

The discipline

  • Store UTC - timestamptz in Postgres, ISO-8601 with offset on the wire (2024-06-01T16:30:00Z).
  • Convert at the edge, in the client, using the user’s zone - not the server’s, not the office’s.
  • Never call a “date-only” value a datetime. A birthday has no timezone. Storing it as local midnight converted to UTC shifts it to the previous day - 00:00 WIB is 17:00 UTC the day before - which bites all of Indonesia.
typescript
new Intl.DateTimeFormat('id-ID', {
  dateStyle: 'medium', timeStyle: 'short',
  timeZone: 'Asia/Jakarta',            // WIB, +07:00
}).format(new Date(order.created_at))

Indonesia-specific traps

  • Three zones (WIB/WITA/WIT) and no DST - so servers “work fine” until a user, provider, or teammate is in a DST country and dates start drifting twice a year.
  • Cron jobs “at midnight” - midnight where? Say Asia/Jakarta explicitly in the scheduler, not in a comment.

Rule of thumb for reviews: any new Date() without a deliberate zone at the display layer, and any naive datetime in storage, gets a comment. This bug class dies by policy, not by fixes.