The hour that happens twice

On the last Sunday of October the clocks in central Europe go back. At 03:00 summer time it becomes 02:00 again, and the hour from 02:00 to 02:59 happens twice.
Our night runner works through a queue while I sleep, and nothing stopped a night from running straight through that hour. So in mid-October we asked a plain question: what does it do when 02:30 happens twice?
Two kinds of time
The runner did its sums on local clock faces. “Pause for 15 minutes” meant: take the local time, add 15 minutes. Python does exactly what you ask here. When two times sit in the same time zone, it adds and compares them as clock faces, and a clock face doesn’t know which 02:30 it is.
Here’s the trap in a few lines. Start at the first 02:50 of that night, add 15 minutes, and ask how long that was:
from datetime import datetime, timedelta, timezone
from zoneinfo import ZoneInfo
tz = ZoneInfo("CET")
start = datetime(2026, 10, 25, 2, 50, tzinfo=tz) # first 02:50, summer time
end = start + timedelta(minutes=15) # "pause for 15 minutes"
print(end) # 2026-10-25 03:05:00+01:00
print(end - start) # 0:15:00
print(end.astimezone(timezone.utc) - start.astimezone(timezone.utc)) # 1:15:00
Same two moments, two answers. On the clock face the pause is 15 minutes. In real time it’s an hour and a quarter. On any other night the two answers agree, and nobody notices which one the code is using.
What we measured
One of us rebuilt that night on a copy of the runner, with a clock that keeps true time, and walked it through the change minute by minute. Four things went wrong.
A short pause gets long. When the runner pauses, it waits 15 minutes and looks again. A pause that starts between 02:45 and 02:59 the first time round gets an end time of, say, 03:05. But 03:05 only exists once, after the second pass. So the pause lasts 75 real minutes instead of 15, and the log line looks exactly the same as on a normal night.
Old data looks fresh. The runner trusts a usage reading for at most 60 minutes. Across the change it trusted one for up to 120. Our first estimate on paper had been about 70 minutes. The measurement said 120, so the estimate went in the bin.
A full window looks empty. At 02:40 summer time, suppose the 5-hour usage window is 95% full and resets at 02:30 winter time, 50 real minutes later. Compare the clock faces and 02:30 looks earlier than 02:40. So the runner decides the reset has already happened and starts work it should have held back.
The report lies about time. A tick that ran 120 real minutes across the change was written in the morning report as 60.
What held up: the end of the night at 08:00, the last start at 07:00, the morning window from 03:00 and the 2-hour guard on a stuck tick all landed on the right moment.
Why no test saw it
Our tests drive the runner with a fake clock: you set the time, the code believes it. That fake clock couldn’t express the second 02:30 at all. And when it ran forward across 02:59 summer time, it skipped an hour.
So the one hour where all four bugs live was the one hour the tests couldn’t stand in. Every test was green, and every test was honest. They just described a world where that hour doesn’t exist.
Four ways out
The measurements came to me as a plain list of options, with what each one costs.
Run it unchanged, and live with all four bugs for one night. Don’t run a night across the hour at all: end it before 02:00, which gives up 7 real hours, or start after 03:00 winter time, which gives up 10 of a 15-hour night. Fix only the budget checks, and keep the long pause and the wrong report line. Or fix the arithmetic properly, in about twelve places, before that night came.
I picked the full fix. Two things came with that choice. If it wasn’t built, checked and installed in time, that night simply wouldn’t run across the hour. And a few one-off reminders set before the change would fire an hour early after it. Nothing bad happens if a reminder comes an hour early, so I left them as they were.
The fix
The rule became: do every sum, comparison and difference in UTC, and keep local time only for display and for the night’s own wall-clock boundaries. Those stay on the wall on purpose: the night ends at 08:00 on the clock, whichever day the clocks change. The change itself was small: one file, 31 lines in and 24 out, built around one helper that turns any time into UTC before the code touches it. It came with a new test clock that keeps the true instant, and with one more test that fails if anyone ever does clock-face arithmetic on “now” again.
The pause that starts at the first 02:50 now ends at the second 02:05: 15 real minutes. On the old code the same pause ended at 03:05, and the test said so in numbers: 4,500 seconds where it expected 900.
It was accepted on 18 October. The full suite passed, 210 tests. Then the 19 new tests were run against the old code, and 12 of them failed. That second run matters more than the first: it shows the new tests can actually see the bug.
It was installed on 24 October, with the runner idle, the day before the clocks went back. The one who usually looks after the runner was busy building something else that day, so another one of us put it in and ran the full suite again on a copy: 210, all green.
The punchline: that Sunday, no night ran through the hour at all. The run started at 06:35, long after the clocks had gone back. The fix was ready for a night that never came. I’d still rather have it that way round than the other.
What’s left
The times the runner prints still carry no offset. On that night “until 02:05” meant the second 02:05. The code knows that. A tired human reading the log at dawn might not.
The next change is on 28 March 2027, when the clocks go forward and 02:00 to 02:59 doesn’t happen at all. That’s a different shape of bug, and we haven’t measured it yet.
A test clock is a model of time. Ours left out the one hour that mattered.
— Max


