skip to content

A column of local wall-clock readings crosses a clock shift. Which two local times cause trouble when a zone is attached, and why?

level: seniorimportance: should knowfreq 45%

answer

  1. one hour twice, one hour never
  2. the mapping stops being one-to-one
  3. ambiguous reading, two candidate moments
  4. verify order and count after attaching

basics

~20 s

At a clock shift one local hour occurs twice and one never occurs. A repeated reading names two possible instants; a skipped one names none. Attaching a zone must therefore raise, choose a side, or move the value.

solid answer

~50 s

A shift changes the displacement from UTC at a fixed moment, so the mapping from instants to clock readings stops being one-to-one for an hour in each direction. When clocks go forward an hour of local readings never occurs, and a row holding one names no moment at all. When clocks go back an hour occurs twice, and a row holding one names two moments an hour apart with nothing in the value to choose between them. Designs differ in what attaching a zone then does: raise, silently take the earlier or the later, take a side from a separate flag, or move a skipped reading past the shift. The symptoms downstream are duplicate keys within one hour, an ordering that is no longer monotonic, and one local hour doubled or empty. The durable fix is upstream — capture the moment, or capture the reading together with the displacement in force.

go deeper

for a junior

Recall the two cases and what causes them: when clocks go forward an hour of local readings never happens, and when they go back an hour happens twice. Both are properties of the zone, not mistakes in the data.

for a middle

Explain why the reading is ambiguous rather than merely unusual, and what a tool has to decide on your behalf in each case. Say that the decision differs by design and is often taken silently.

for a senior

Diagnose from symptoms: a natural key that collides once a year, an ordering that is not monotonic, an hourly total doubled or empty. Then show the upstream fix and the two cheap checks that catch a silent resolution.

for a principal

Decide what the platform guarantees at capture. Mandating moments at every producer costs coordination with teams you do not own; allowing local readings costs a permanent, seasonal defect class that surfaces once a year in whichever pipeline forgot.

## What a shift does to the local clock A zone that shifts its clocks seasonally does it by changing the displacement from UTC at a fixed moment. The world timeline is untouched — no moment is created or destroyed — but the mapping from moments to clock readings stops being one-to-one for an hour in each direction: - **When clocks go forward**, an hour of local readings is skipped. If the clock jumps from 02:00 to 03:00, then 02:30 **never occurred** in that zone that day, and a row holding it names no moment at all. - **When clocks go back**, an hour of local readings occurs twice. If the clock returns from 03:00 to 02:00, then 02:30 occurred **twice**, an hour apart, and a row holding it names two moments with nothing in the value to choose between them. Everything else in this subject follows from those two sentences. ## Why it reaches your column at all It reaches you whenever the capture side recorded a clock reading rather than a moment: a device writing its local time, an export from a system whose display zone is the office's, a form where a human typed a time, a log line formatted locally with no displacement written out. It does not reach you if the capture side recorded the moment, which is the whole argument for doing so. ## What attaching a zone does with the two cases Designs differ here more than anywhere else in this subject, and the difference is invisible unless you go looking: | Case | What the local reading names | Behaviours seen across designs | |---|---|---| | The repeated hour | Two moments, one each side of the shift | Raise as ambiguous; silently take the earlier; silently take the later; take the side supplied by a separate flag | | The skipped hour | No moment at all | Raise as nonexistent; move it forward past the shift; move it back; produce the absent-time marker | A design that raises hands you a decision to make. A design that resolves silently hands you a column that looks complete and is wrong for at most an hour of rows a year — which sounds negligible until that hour is a settlement window, a shift handover or an overnight batch. ## The symptoms in data 1. **Duplicate keys inside one hour.** If the local stamp is part of a natural key, the repeated hour produces colliding rows once a year, and a de-duplication step then drops real records. 2. **An ordering that is not monotonic.** Sorting on the local column places the second pass through the repeated hour among the first pass's rows. Any operation whose precondition is monotonic time order is then running on an input that violates it, and in several designs nothing verifies that precondition. 3. **An hour counted twice, or an hour missing.** A total per local hour shows one hour with roughly double the traffic, or one hour with none, and the year-on-year comparison reads like an incident. 4. **A hole in a derived sequence.** A pipeline expecting one position per local hour finds the skipped hour absent, and either records a hole or shifts everything after it by one position. ## What to do about it - **Capture moments.** The only durable fix is upstream: record the moment, or record the clock reading together with the displacement in force. Either is unambiguous; a bare local reading is not. - **Carry a disambiguating marker when you cannot.** Where a feed must stay in local wall-clock, a per-row marker for which pass through the repeated hour a record belongs to is the minimum that makes the column recoverable. - **Make the attachment explicit.** When you attach a zone to a local column, decide in the code what happens to ambiguous and skipped readings rather than accepting whatever the default is, and write the decision where the next reader will find it. - **Verify after attaching, not before.** Check that the resulting moments come out monotonic where you expect them to, and check the row count against what the span should contain. Both cost one pass and catch a silent resolution. - **Do not sort the local column to establish time order.** Sort on the moment. The local column is a rendering. ## What an interviewer is listening for That you can name both pathologies unprompted, in both directions, and that you say what varies rather than asserting one behaviour as the rule. The weak answer is that the tool will tell you; it may, and it may not. The strong answer moves the problem upstream to the moment of capture and, where that is impossible, makes the resolution an explicit reviewed decision with a check standing behind it.

  • A feed must keep local wall-clock stamps. What is the minimum that makes them recoverable?
    A per-row marker saying which side of the shift a record belongs to, or the displacement that was in force when it was captured. Either resolves the repeated hour, and both make a skipped reading visibly impossible rather than silently moved.
  • Which downstream steps are most exposed to a silently resolved ambiguous hour?
    Anything carrying an unverified monotonic-order precondition, anything using the local stamp inside a natural key, and any total per local hour. The first runs on a sequence that is not ordered, the second collides once a year, and the third shows one hour doubled or empty.

saying these in an interview costs you the question

  • Every local clock reading names exactly one moment.
  • A skipped local time is just a data-entry error.
  • Sorting the local column puts records in chronological order.
  • The tool will raise whenever a local reading is ambiguous.
  • A repeated hour can be resolved by taking the earlier moment, with no consequence.