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 -
timestamptzin 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.
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/Jakartaexplicitly 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.