If you’re stitching together hourly forecast slices across a DST boundary and leaning on time_epoch as your single source of truth, you’re probably fine — right up until the twice-a-year moment you aren’t.
Here’s what actually trips people up. The time_epoch in hourly forecast responses is a true Unix timestamp in UTC seconds. That part is correct. The problem isn’t the epoch value itself — it’s the human-readable time field sitting next to it, which is in the location’s local time, and the interaction between both fields when your app crosses a DST boundary mid-forecast window.
Where the stitching goes wrong
Suppose you’re building a 10-day display that requests three separate API calls — one for the current day, one for days 2–5, and one for days 6–10. You key your in-memory or Redis cache on time_epoch. That’s the right instinct. But if you’re also using the string time field anywhere for grouping or display ordering — say, to bucket hourly entries into calendar days for a UI — you can end up with a day that has 23 hours or 25 hours depending on which direction the clock turns. The epoch-based sort will be correct. The local-string-based grouping will silently produce a miscounted bucket.
The forecast response for a US location will include something like:
{
"time": "2025-03-09 02:00",
"time_epoch": 1741499400
}
Then at the transition:
{
"time": "2025-03-09 03:00",
"time_epoch": 1741503000
}
The epoch gap is 3600 seconds — one hour, as expected. But the day that runs from midnight local time on March 9 to midnight local time on March 10 is only 23 hours long. If you’re summing hourly precipitation across a calendar day using local-time string boundaries, your accumulation window is 23 hours, not 24. For a display-only app, harmless. For anything feeding irrigation scheduling, energy demand estimation, or a storm-total tracker, quietly wrong.
The offset drift issue in multi-call stitching
There’s a second failure mode that’s subtler. When you make two separate API calls for overlapping or adjacent time windows — a common pattern for reducing response payload size — the UTC offset baked into the response’s location.localtime and the offset implied by comparing time to time_epoch can differ across the two responses if a DST transition falls between the two call times.
Call 1 made at 01:30 UTC on March 9: offset is -5. Call 2 made at 07:00 UTC on March 9 (after the transition): offset is now -4. If your stitching logic infers the offset from the first call and applies it uniformly to both response sets before merging, the post-transition hours will be off by one. You’ll stitch a gap or a duplicate depending on how you handle the overlap.
The fix is straightforward once you see it: never infer offset from one response and apply it to another. Derive local time from time_epoch plus the offset reported in that specific response, or better, skip local-time derivation entirely and do all ordering, bucketing, and deduplication against the epoch values only. Only convert to local display strings at the last possible moment, using the offset from the response that produced each record.
Cache key design near DST transitions
If you’re caching hourly forecast data — which you should be, given API quota costs — your cache key almost certainly includes something time-based. The danger is keying on a local date string like "2025-03-09" when the data covers a DST-affected day. The 23-hour day and the 25-hour day look identical from a date-string key. Your cache TTL logic, if it’s based on “number of hours covered,” will be off for those two days per year per timezone.
We store forecast chunks keyed on {location_id}:{epoch_start}:{epoch_end} and set the TTL relative to the epoch values, not wall-clock hours. It costs a little extra logic at write time but means the DST edge cases self-correct — the key is unique regardless of how many local-clock hours are in the window, and the TTL accurately reflects how stale the data is in real elapsed time.
The practical rule for safe epoch handling
Treat time_epoch as your ordering and deduplication key. Full stop. Use it to sort, to merge overlapping forecast slices, and to detect gaps. Use the local time string for nothing except display — and even then, re-derive it from epoch plus the per-response offset rather than trusting the string directly if you’ve done any stitching between responses.
For grouping hourly data into calendar days on behalf of a user, group by floor((time_epoch + utc_offset_seconds) / 86400) rather than by parsing the date portion of the time string. That expression gives you a day-bucket that correctly handles DST because it uses a fixed-length day in UTC space, shifted by the offset — rather than relying on a local calendar day that may be 23 or 25 hours. The reason this works where string parsing doesn’t: you’re doing integer arithmetic on a monotonically increasing value, so the DST discontinuity in local clock time simply doesn’t appear in the calculation.
One real caveat here: this gives you a correct epoch-anchored day, not necessarily the same day boundary a local person would use if they think of midnight as the separator. In practice those agree except on DST transition dates. For scheduling, accumulation, and alerting, the epoch-anchored version is what you actually want. For a human-readable calendar display, you may need to handle the transition dates explicitly and accept that one displayed day will have a different number of slots.
Quick implementation sketch
Minimum viable stitching pattern in pseudocode:
- Collect all hourly objects from all API responses into a flat list.
- Deduplicate by
time_epoch— last-write-wins if the same epoch appears in two responses (the more recent API call is fresher). - Sort ascending by
time_epoch. - When bucketing into days:
day_key = (time_epoch + location_utc_offset_seconds) // 86400— storelocation_utc_offset_secondsper record, not globally, since it may change across a DST transition within a single stitched window. - Only generate display strings from epoch at render time, using the per-record offset.
The per-record offset storage sounds like overkill until it’s the thing that silently fixes your DST edge case without you having to think about it twice yearly.
DST transitions happen across US, EU, and Australian timezones on different calendar dates, which means if your app operates across all three regions, you’re dealing with DST edges scattered across roughly six months of the year. It compounds: a bug in your stitching logic that only surfaces on transition days is exactly the kind of bug that sits unfixed for a long time because nobody’s looking at weather data at 2 a.m. on a Sunday in March.
Worth sitting with: does your current cache invalidation logic know the difference between a 23-hour day and a 24-hour day? If not, that’s the first thing to audit before the next clock change.
