Build, Buy, or Vibe-Code? · For engineers
AI-written code and time zones: fine until you deploy
We asked an AI model for date code four ways. Told the city or zone, it was right on every server, daylight saving included. Not told, it broke on UTC.
Short answer Naming the business's city or time zone in the prompt made AI-written date code right in all nine runs we checked, daylight saving dates included where tested. Without it, all three booking APIs used the server's clock; on a UTC server, the next six hours of slots vanished.
At 9:00 on a Tuesday morning in Chicago, a patient opens a clinic's booking page and asks for 11:00. The server answers "cannot book a slot in the past". Today's list shows three free slots, the first at 15:30. The other twelve are free as well; the server just thinks they are over.
That is what three AI-written booking APIs did in our test when the server ran on UTC. On a machine set to Chicago time, the same code booked the 11:00 slot and offered all fifteen. In our prototype-cliff test we noticed this in passing. This time we measured it, and checked what fixes it.
What we tested
We asked Claude Sonnet, run cleanly from the command line with no tools, for date and time code in the four ways in the table below, three times each. The checks were functional only, against known answers for Chicago, where daylight saving time ended at 2:00 a.m. on Sunday 1 November 2026 and starts again at 2:00 a.m. on Sunday 14 March 2027Source 1. It is one model, three runs per prompt and one city, so read it as a measured example, not a rate.
| What the prompt said | What the code used | Result |
|---|---|---|
| A booking API for "my dental clinic", no city | The server's own clock | Server on UTC: 3 of 15 slots offered, 11:00 refused. Server on Chicago time: 15 offered, 11:00 booked. 3 of 3 runs |
| The same API, with a one-page brief that names Chicago | America/Chicago | Server on UTC: 15 offered, 11:00 booked. 3 of 3 |
| "A clinic in Chicago": appointment and reminder times in UTC | America/Chicago, hard-coded, with Intl | 4 of 4 checks on servers in UTC, Chicago and Los Angeles. 3 of 3 |
| Convert a date, a time and an IANA time zone to UTC | The zone passed in, with Intl | 9 of 9 checks, including both daylight saving changes, on servers in five time zones. 3 of 3 |
The line that breaks
The three plain servers wrote the "is it in the past?" check a little differently, but all of them built the appointment time from the server's local clock: new Date(y, mo - 1, d, h, mi) <= new Date() in one, getHours() and getDate() in the other two. In JavaScript, those date parts are evaluated against the local time zone, rather than UTCSource 2. Local means wherever the code runs. On a developer's laptop in Chicago, that is Chicago. On AWS Lambda, the default time zone is UTCSource 3, and many other hosts and containers start on UTC as well, so check yours.
In winter, Chicago is six hours behind UTC. On a UTC server, every slot in the next six hours looks as if it has already happened, so a morning patient sees a nearly empty day. Nothing crashes and no error is logged, and on a developer's laptop in Chicago everything works.
Told the city, the code was right
One fact changes the result. When the prompt said the clinic was in Chicago, all three runs hard-coded America/Chicago, converted with Intl.DateTimeFormat, and got every answer right on servers in UTC, Chicago and Los Angeles. Given the time zone as a parameter, all three got nine of nine cases right on servers in five time zones, including a reminder the day before each daylight saving change. The booking servers built from a one-page brief that names Chicago used the clinic's zone too, and booked the 11:00 slot on a UTC server.
Two cases are worth a decision of your own. At 1:30 a.m. on 1 November, the clock shows 1:30 a.m. twice; all three runs picked the first one. And 2:30 a.m. on 14 March does not exist in Chicago, because clocks jump from 2:00 to 3:00; all three quietly turned it into 3:30. That is the default of JavaScript's new Temporal API as well: later for gaps and earlier for ambiguitiesSource 4. It is a sensible default for a reminder. For a booking, you may prefer to refuse the time and ask the patient again. Neither the prompt nor the code raised the question.
What to do
- Say where the business is. Put the city, or better the IANA zone such as
America/Chicago, in the prompt and in your one-page brief, so every change the AI makes starts from it. - Make the zone a setting. A second location in another time zone should be a configuration change, not a search through the code for
America/Chicago. - Run your tests on a different clock. Run the suite with
TZ=UTC, and once more with a zone far from yours such asTZ=Pacific/Auckland. Code that depends on the machine's clock gives different answers on each setting, so a test with a fixed expected time fails on whichever one is wrong. - Test the dangerous dates. For the US this season: 1 November 2026, when 1:00 to 2:00 a.m. happens twice, and 14 March 2027, when 2:00 to 3:00 a.m. does not exist. Add the day before each, for reminders.
- Store the instant and what the person chose. Save the UTC instant and, next to it, the date, time and zone the patient picked, so you can recompute if the rules change.
Next step
Get new posts as they come out
Every new post, in plain English and in depth. Follow the RSS feed.
Sources
- Daylight Saving Time (NIST). Retrieved . ↩
- Date() constructor (MDN). Retrieved . ↩
- Working with Lambda environment variables (AWS documentation). Retrieved . ↩
- Temporal.ZonedDateTime (MDN). Retrieved . ↩