ProgramIn Studio All articles
Tooling

Twice Past Midnight: A Clock-Change Drill for Anything on a Timer

ProgramIn Studio
Twice Past Midnight: A Clock-Change Drill for Anything on a Timer

Photo: Lankyrider, CC BY-SA 4.0, via Wikimedia Commons

The clocks went back on 25 October this year, and like every year a handful of studios discovered on Monday morning that something had quietly run twice, or not at all, or at 02:00 instead of 09:00. The next one lands on 28 March 2027, so there's plenty of time to be smug about it — but only if you actually do the work now, while it's boring and nothing is on fire.

Here's the thing that makes this a proper engineering problem rather than a pub moan: British Summer Time doesn't just shift everything by an hour. It creates an hour with two identities and, in spring, an hour that simply doesn't exist. Anything that reasons about wall-clock time is going to have opinions about both, and most of those opinions are wrong.

The two awkward hours, plainly

On the last Sunday in March, local time jumps from 00:59 straight to 02:00. The half hour either side of 01:30 never happens. If you've scheduled a nightly reconciliation at 01:30, it has no scheduled instant that day. Cron will do something — usually fire at a time you didn't intend, or skip entirely, depending on the daemon and how it's configured — and you'll find out via a support ticket rather than an alert.

On the last Sunday in October, 01:00 to 01:59 comes round twice. A job that runs hourly gets twenty-five runs instead of twenty-four. A job that keys on the local date gets invited to a party it already attended.

Both of these are fine if you've decided what should happen. Both are miserable if you haven't.

Store the instant, not the impression

The single highest-value habit is dull and unglamorous: persist timestamps in UTC, and store the timezone identifier alongside them when the human meaning matters — Europe/London, not +01:00 and definitely not "BST". An offset tells you where the clock hands were pointing at one moment. It tells you nothing about what happens next week.

scheduled_at_utc   timestamptz  not null
schedule_timezone  text         not null default 'Europe/London'

When someone asks for "the daily digest at half eight in the morning", you are storing a rule, not a moment: 08:30 in Europe/London, every weekday. Compute the next occurrence by asking a timezone-aware library to advance to the next calendar day in that zone and then resolve 08:30. Do not add 86,400 seconds. Ever. Adding a day's worth of seconds is how you end up an hour out for half the year and no one notices until the Christmas rota.

On the rendering side, keep the conversion late and explicit — Luxon, date-fns-tz, Temporal, Python's zoneinfo, whatever fits your stack — and pass the zone in rather than relying on the server's TZ. If your app server thinks it lives in UTC and your container thinks it lives in Europe/London, you have two clocks and one bug report waiting to happen.

Make runs idempotent, then prove it

The autumn repeat is a gift if your jobs are idempotent and a nuisance if they aren't. The practical pattern is a run ledger: a row keyed on the job name plus the intended instant or the business date, written in the same transaction as the work. Second attempt hits the unique constraint, job exits politely, nobody's card gets charged twice.

Slightly more subtle: decide whether "daily at midnight" means every calendar day or every 24 hours. Those are the same thing for 363 days a year and different things on two of them. Write the decision down in a comment, because the next person to touch the scheduler will assume the other one.

The four tests

You don't need a big harness. You need to be able to lie to your code about what time it is, and then check four cases:

  1. Spring forward, the missing hour. Freeze the clock either side of the gap and ask for the next occurrence of 01:30. Assert the date and time you get back, in UTC. Assert it twice: once for a job that should roll to 02:30, once for a job that should skip the day.
  2. Autumn back, the doubled hour. Ask for the next hourly occurrence from 00:30 and step forward four times. Count the runs. You want five, and you want the two 01:xx runs to be distinguishable in your ledger.
  3. The day either side. A plain "next 09:00" from 09:00 the day before the change should land 24 hours later; from the day after the spring change, 23. Both should render as 09:00 local. If your code returns 08:00 or 10:00, you've found something.
  4. The far future. Compute the next occurrence of the same rule a year out and confirm it flips offset correctly. This is the one that catches hard-coded +01:00.

Where the language supports it, inject the clock rather than calling Date.now() inline. It's a five-minute change that turns untestable scheduling logic into ordinary code.

The weekend checklist

We run this on the Friday before each change, and it takes under an hour for a typical studio stack:

The upside of caring

None of this is difficult, which is exactly why it's easy to skip. But clock-change behaviour is one of those quiet signals — a client whose monthly invoice ran twice at 01:15 on a Sunday in October learns something about you that no amount of case-study copy can undo. An hour of pessimism twice a year keeps that conversation from happening at all.

And if you only do one thing between now and 28 March 2027: grep the codebase for + 24 * 60 * 60 and look at each result with genuine suspicion.

All Articles

Related Articles

Staging Is Not a Landfill: The Friday Reset That Keeps Demos Honest

Staging Is Not a Landfill: The Friday Reset That Keeps Demos Honest

The Coach C Audit: Building a Studio Site That Survives Half a Bar of Signal

The Coach C Audit: Building a Studio Site That Survives Half a Bar of Signal

Assume They're Exhausted: Designing Forms for the Worst Tuesday of Someone's Week

Assume They're Exhausted: Designing Forms for the Worst Tuesday of Someone's Week