The forecast’s local hour: time zones and daylight saving time

Display a skipped or repeated local hour while preserving the UTC instant, order and every forecast value.

The rhythm of light and dark windows represents repeated and missing local hours.

An hourly forecast shows “02:00” twice. A developer removes one row as a duplicate, making the table look tidier. But the repeated label takes a separate forecast instant with it. When clocks turn back in autumn, the same local hour can correspond to two different UTC instants.

Spring brings another temptation: insert the missing “02:00” so the sequence looks continuous. The interface then creates a value for a local time that did not occur that day. Both errors begin with the same decision: using a clock label as the identity of a weather record.

We will examine a small synthetic timeline. Its temperature values are invented; there are no real forecasts or provider requests. The time zones and transition instants are real and come from a specified edition of the rules database. The task is to preserve every input instant, its order and its value while changing only the local label.

UTC holds the series together; local time explains it to the reader

A single series already has a known place, quantity and forecast revision. Within that series, the UTC instant identifies a sample. In a complete product, time alone is insufficient: two models or two forecast revisions can supply different values for the same instant. Comparing them requires a broader domain identity.

Each teaching input has utc and reading. Both remain in the output, alongside the zone, local date and time, text offset and offset in seconds. The result remains ordered by UTC. Neither 02:00 nor the hour's position in a calendar day becomes the row key.

Changing the representation does not change the quantity's meaning either. Temperature at an instant remains temperature at that same instant. A precipitation total over an interval requires both boundary labels to be converted while preserving their meaning. Renaming an hour does not turn an interval total into an instantaneous measurement.

A zone name supplies rules; an offset describes one instant

Europe/Berlin identifies a set of time rules. +01:00 gives only the offset from UTC at a particular instant. One winter offset cannot tell us how to display a summer forecast. A short abbreviation does not replace an explicit zone name either.

IANA explains that its time zone database changes as civil time rules change. This exercise pins edition 2026f for its expected mappings; that does not mean PHP's system database uses the same edition. The pinned rules make the expectations reproducible without promising that today's rules will remain unchanged forever.

The product must choose the display zone. A forecast for a selected town would naturally show that place's time; a user might separately request their own zone. The heading above the timeline should explain the choice. Page language, server timezone or the browser's current setting does not by itself determine a town's zone. The teaching model receives it explicitly and does not perform geographic zone lookup from coordinates.

In spring, 02:00 is skipped

Under the Berlin rules in IANA 2026f, on 29 March 2026, 00:00 UTC displays as 01:00 +01:00, while the next 01:00 UTC displays as 03:00 +02:00. The local label 02:00 is skipped even though an ordinary hour separates the two input instants.

The adjacent synthetic temperatures are 5 and 6. They remain adjacent samples. There is no reason to insert zero, repeat 5 or calculate an intermediate temperature merely to make the hour list look neat. Each of those actions would add a new claim about the weather.

A missing local label must be distinguished from a missing input UTC record. If the source genuinely supplied no sample, timezone conversion cannot restore it. An explicit null in a record also remains unchanged. The exercise performs no interpolation or automatic filling.

A useful check follows the input through to the output: the row count stays the same, every UTC instant retains its value and the sequence remains unchanged. Comparing counts alone is insufficient because one record could be lost and replaced with another. The oracle therefore contains complete rows. A monitoring rule should likewise inspect UTC steps if its question is whether the next sample arrived, rather than whether every possible local clock label exists.

This also affects day selection. A calendar day should not be constructed as “start plus 86,400 seconds.” For the specified spring date in Berlin, the interval between local midnights is shorter than usual; for the autumn date, it is longer. Weather-day completeness needs separate verification for the required quantity and actual boundaries. Our projector does not calculate complete days.

In autumn, the two 02:00 labels have different offsets

On 25 October 2026, turning the clock back in the same zone produces this pair:

UTC Local time Offset Synthetic value
00:00 02:00 +02:00 11
01:00 02:00 +01:00 12

These are two samples, rather than two ways to format one record. The first belongs before the second. A dictionary keyed by local date and hour would overwrite one of them. Sorting only by local text also loses the required time reference. UTC instants already provide a reliable order.

Readers benefit from seeing both labels with their offsets, while the zone name remains visible for the whole timeline. The interface can add an explanation of the clock change when useful. Labels such as “first” and “second” without an offset depend on context and transfer less clearly into exports or saved selections.

A reference to the selected row should retain its UTC instant and domain context. If the user changes the display zone, the reference will still point to the same sample. Saving only the text “02:00” would require another ambiguous interpretation the next time it is opened.

A control without a seasonal transition matters too

For Asia/Kolkata, the IANA entry specifies a constant +05:30 offset on the selected dates. The same instants 00:00, 01:00 and 02:00 UTC become 05:30, 06:30 and 07:30. This control has no seasonal gap or repetition.

The half-hour offset exposes another mistake: an hourly UTC grid does not have to land on minute zero of each local hour. Rounding 05:30 to 05:00 changes the label's meaning. If the product needs another grid, that is a separate data transformation with its own method.

Additional pairs in the example fall immediately before a transition and exactly on its boundary, one second apart. They check when the offset changes. They are technical control inputs, not hourly measurements with greater precision. Ordinary weather samples do not acquire more precise data through formatting.

Converting a known instant is easier than guessing a local one

The central PHP operation is short:

$local = $instant->setTimezone(new DateTimeZone('Europe/Berlin'));

The DateTimeImmutable::setTimezone contract preserves the instant while creating an object with another timezone. Before that operation, the teaching code strictly accepts a complete UTC string with Z and seconds. It validates the calendar value and increasing instants; duplicate UTC values and reverse order reject the entire call.

Only the two named zones in this exercise, up to 168 rows, and finite numbers or null are supported. These are local example limits. Strings with an explicit numeric offset are also outside its input format, although that format can identify an instant unambiguously in a broader contract. Here, the preceding adapter must already provide canonical UTC.

A user's request for “02:00 local time” is a different problem. In autumn there can be two matches; in spring, none. It needs an explicit clarification or rejection policy. This model does not solve the reverse conversion or rely on an arbitrary parser choice.

Verification must see every sample

Before implementation, six input sets and twenty expected UTC/local mappings were frozen from the published rules. They include both seasonal transitions, the control zone and exact boundaries. A native run on PHP 8.5.12 passed 22 cases: six frozen golden series with 20 complete rows, plus 16 other cases. All 20 expected rows matched; the other checks cover ordering, rejection, gaps and independence from the system timezone. These are native cases, not the full PHPUnit suite.

A separate Python zoneinfo run compared all twenty pairs with the frozen expectations. It read specific TZif bytes from the tzdata 2026.6 package, which contains IANA 2026f. The zoneinfo documentation explains its different time-data sources; explicit selection here prevented substitution by the system database. This result confirms the mappings in that separate check and does not constitute execution of the PHP class.

In this PHP run, the integer size was 8 bytes, and timezone_version_get returned 0.system. The system tzdata and TZif identities were recorded separately. The Python check using 2026f does not prove that PHP uses that edition; matching zone names without a known data edition do not guarantee matching rules in two environments.

If local labels are cached, the selected zone and rule edition must participate in the update policy. After changing the time database, check significant transitions and rebuild the derived presentation where necessary while retaining the original UTC instants. Readers can then see a skipped or repeated hour with an explanation, and every forecast value remains attached to its own time.

  1. Symfony Core Scheduled publication: time, time zones and repeated execution
  2. Weather A newer forecast is shorter: updating the next hours while retaining the long horizon
  3. Weather Degrees, wind and precipitation: normalize units without losing meaning