Modern Apps git

← Modern-Apps.git

weather: forecast times resolve the location zone per epoch, not a fetch-time offset

Commit
d30269189b58fca9973e9b19b2f98c62c1b48a27
Author
Vayun Mathur <[email protected]>
When
2026-12-01 07:34 UTC (5 days ago)
Parents
f9ffb82
WxBundleMapper.epochToNaiveLocal converted every epoch with
the bundle's single utcOffset — the offset at the fetch
instant — ignoring the bundle's IANA zone. Across a DST
transition every forecast time on the far side displayed one
hour wrong: a New York bundle fetched 2026-03-06 (EST) shows
the 2026-03-09 sunrise (11:12Z = 07:12 EDT) at 06:12, and the
spring-forward hourly strip displays a nonexistent 2 AM with
every later hour early. Epochs round-tripped through the
same fixed offset, so only the wall-clock labels were wrong.
This hit every DST-observing location for about a week
twice a year.

Conversions now resolve the bundle's zone per epoch (fixed
offset only when the zone cannot resolve, including the UTC
placeholder default); DateTimeFormat gains zone overloads
(parse/format/strip-hour/axis-label) and consumers switch to
them: forecast column, hourly card, weather blocks, sun/moon
blocks, metric series, precipitation, and the assistant
intent. AGENTS.md documents the convention. Three new tests
failed pre-fix on the values above. Pack composition, unit
conversions and location handling were audited against the
parity fixtures and cleared. Verified: :weather:
testDevUnitTest 246 tests pass; lint errors are pre-existing
on untouched files.

Diff

weather/AGENTS.md
diff --git a/weather/AGENTS.md b/weather/AGENTS.mdindex 2aa3706ea5..c7dbdfb429 100644--- a/weather/AGENTS.md+++ b/weather/AGENTS.md@@ -22,7 +22,7 @@ _Install: ./install weather (dev by default)._ - Unit system follows the device locale (`platform/SystemUnits`) — format in `domain/`, never in `ui/` - Map shading is sampled on device from the R2 run tiles in `network/WxStatic`; the Rust `.om` bridge (`domain/map/OmTilesNative`) is not on the read path - Widgets must render from cache alone — never network on the widget path-- Map `valid_times` are UTC; the graph sheet's selected hour is a naive location-local ISO string and is converted with the forecast's `utcOffsetSeconds` (`localIsoToUtcIso`) before seeding the map's time index+- Map `valid_times` are UTC; the graph sheet's selected hour is a naive location-local ISO string and is converted with the forecast's IANA zone (`localIsoToUtcIso`, zone overload) before seeding the map's time index — all epoch↔local-ISO conversion goes through the bundle's `tz` zone so the offset in force at each instant applies across DST transitions; the fetch-time `utcOffsetSeconds` is only the fallback when the zone id does not resolve  ## Key files ### Root — entry + navigation
weather/src/main/java/com/vayunmathur/weather/domain/DateTimeFormat.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/domain/DateTimeFormat.kt b/weather/src/main/java/com/vayunmathur/weather/domain/DateTimeFormat.ktindex c0c7b045fc..5707ad7775 100644--- a/weather/src/main/java/com/vayunmathur/weather/domain/DateTimeFormat.kt+++ b/weather/src/main/java/com/vayunmathur/weather/domain/DateTimeFormat.kt@@ -1,6 +1,7 @@ package com.vayunmathur.weather.domain  import com.vayunmathur.library.ui.DateString+import com.vayunmathur.weather.network.ForecastResponse import com.vayunmathur.library.util.localizedAmPmMarker import kotlinx.datetime.format.DateTimeFormat import com.vayunmathur.library.util.DateNameStyle@@ -76,18 +77,48 @@ private fun localTimeAt(epochSec: Long, utcOffsetSeconds: Int? = null): LocalTim     } } +/** Resolve an IANA time-zone id (the bundle's `tz`), null when unknown. */+fun resolveTimeZone(tzId: String?): TimeZone? =+    tzId?.takeIf { it.isNotBlank() }?.let { runCatching { TimeZone.of(it) }.getOrNull() }++/**+ * The forecast location's IANA zone, null when its `timezone` id is+ * unresolvable. A `timezone` of "UTC" with a non-zero `utcOffsetSeconds`+ * is the mapper's fixed-offset fallback shape (no real zone supplied),+ * so it resolves to null here too and callers keep the fixed offset.+ */+fun ForecastResponse.locationZone(): TimeZone? {+    if (timezone == "UTC" && utcOffsetSeconds != 0) return null+    return resolveTimeZone(timezone)+}++private fun localTimeAt(epochSec: Long, zone: TimeZone): LocalTime =+    Instant.fromEpochSeconds(epochSec).toLocalDateTime(zone).time+ /** Hour-axis label "3 PM" / "09:00" for an epoch second in the location's zone. */ fun formatHourAxisLabel(epochSec: Long, use24Hour: Boolean, utcOffsetSeconds: Int? = null): String =     DateString.hourLabel(localTimeAt(epochSec, utcOffsetSeconds), use24Hour) +/** Hour-axis label "3 PM" / "09:00" for an epoch second in [zone] (DST-aware). */+fun formatHourAxisLabel(epochSec: Long, use24Hour: Boolean, zone: TimeZone): String =+    DateString.hourLabel(localTimeAt(epochSec, zone), use24Hour)+ /** Hourly-strip label "3 PM" / "9" for an epoch second in the location's zone. */ fun formatStripHour(epochSec: Long, use24Hour: Boolean, utcOffsetSeconds: Int? = null): String =     localTimeAt(epochSec, utcOffsetSeconds).format(if (use24Hour) HourOfDayBare else HourAmPm) +/** Hourly-strip label "3 PM" / "9" for an epoch second in [zone] (DST-aware). */+fun formatStripHour(epochSec: Long, use24Hour: Boolean, zone: TimeZone): String =+    localTimeAt(epochSec, zone).format(if (use24Hour) HourOfDayBare else HourAmPm)+ /** Clock time "3:05 PM" / "15:00" for an epoch second in the location's zone. */ fun formatClockTime(epochSec: Long, use24Hour: Boolean, utcOffsetSeconds: Int? = null): String =     DateString.time(localTimeAt(epochSec, utcOffsetSeconds), use24Hour) +/** Clock time "3:05 PM" / "15:00" for an epoch second in [zone] (DST-aware). */+fun formatClockTime(epochSec: Long, use24Hour: Boolean, zone: TimeZone): String =+    DateString.time(localTimeAt(epochSec, zone), use24Hour)+ /** "Wed 25 Jun" for an ISO date like 2026-06-25; echoes the input on parse failure. */ fun formatDayMonthLabel(isoDate: String): String {     val date = runCatching { LocalDate.parse(isoDate) }.getOrNull() ?: return isoDate@@ -140,6 +171,25 @@ fun formatUtcIso(epochSec: Long): String { fun localIsoToUtcIso(iso: String, utcOffsetSec: Int): String? =     parseLocalIsoToEpochSec(iso, utcOffsetSec)?.let { formatUtcIso(it) } +/**+ * Convert a naive location-local ISO string to the UTC ISO shape the map's+ * `valid_times` use, via the location's IANA [zone] (DST-aware: the offset+ * is the one in force at that local time, not the fetch-time offset).+ * Null when [iso] does not parse.+ */+fun localIsoToUtcIso(iso: String, zone: TimeZone): String? =+    parseLocalIsoToEpochSec(iso, zone)?.let { formatUtcIso(it) }++/**+ * Recover a true epoch from a naive location-local ISO string using the+ * location's IANA [zone] — the offset is the one in force at that local+ * time, so strings on the far side of a DST transition round-trip exactly.+ * Null when [iso] does not parse.+ */+fun parseLocalIsoToEpochSec(iso: String, zone: TimeZone): Long? = runCatching {+    LocalDateTime.parse(iso).toInstant(zone).epochSeconds+}.getOrNull()+ /**  * The bundle mapper emits local-time ISO strings with no offset (e.g.  * `2024-05-30T05:42`). Combine with `utc_offset_seconds` from the response to
weather/src/main/java/com/vayunmathur/weather/domain/MetricSeries.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/domain/MetricSeries.kt b/weather/src/main/java/com/vayunmathur/weather/domain/MetricSeries.ktindex 5dc9c4443d..dc11012900 100644--- a/weather/src/main/java/com/vayunmathur/weather/domain/MetricSeries.kt+++ b/weather/src/main/java/com/vayunmathur/weather/domain/MetricSeries.kt@@ -176,7 +176,7 @@ fun metricSeries(     val hourly = forecast.hourly ?: return emptyList()     val raw = rawSeries(hourly, metric)     val targetDate = targetDateFor(forecast, selected)-    return collectDayPoints(hourly.time, raw, targetDate, forecast.utcOffsetSeconds)+    return collectDayPoints(hourly.time, raw, targetDate, forecast) }  private fun rawSeries(@@ -214,14 +214,18 @@ private fun collectDayPoints(     times: List<String>,     raw: List<Double?>,     targetDate: String,-    utcOffsetSeconds: Int,+    forecast: ForecastResponse, ): List<MetricPoint> {+    val zone = forecast.locationZone()     val out = ArrayList<MetricPoint>()     for (i in times.indices) {         val value = raw.getOrNull(i) ?: continue         val iso = times[i]         if (iso.substringBefore('T') != targetDate) continue-        val epoch = parseLocalIsoToEpochSec(iso, utcOffsetSeconds) ?: continue+        // Zone-aware when the IANA zone resolves (the offset in force at+        // that local time); the fetch-time offset is the fallback.+        val epoch = (zone?.let { parseLocalIsoToEpochSec(iso, it) }+            ?: parseLocalIsoToEpochSec(iso, forecast.utcOffsetSeconds)) ?: continue         out.add(MetricPoint(epoch, value))     }     return out
weather/src/main/java/com/vayunmathur/weather/intents/GetWeatherIntent.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/intents/GetWeatherIntent.kt b/weather/src/main/java/com/vayunmathur/weather/intents/GetWeatherIntent.ktindex 440dabd8d6..51d82f9771 100644--- a/weather/src/main/java/com/vayunmathur/weather/intents/GetWeatherIntent.kt+++ b/weather/src/main/java/com/vayunmathur/weather/intents/GetWeatherIntent.kt@@ -6,6 +6,7 @@ import com.vayunmathur.library.util.AssistantIntent import com.vayunmathur.weather.network.ForecastResponse import com.vayunmathur.weather.network.WeatherApi import com.vayunmathur.weather.domain.compassDirection+import com.vayunmathur.weather.domain.locationZone import com.vayunmathur.weather.domain.parseLocalIsoToEpochSec import com.vayunmathur.weather.domain.todayIndex import com.vayunmathur.weather.domain.weatherConditionForCode@@ -65,8 +66,13 @@ internal fun ForecastResponse.toWeatherData(context: Context, locationName: Stri     val lo = daily?.temperatureMin?.getOrNull(t) ?: current.temperature     val precip = daily?.precipitationProbabilityMax?.getOrNull(t) ?: 0     val uv = daily?.uvIndexMax?.getOrNull(t) ?: 0.0-    val sunrise = daily?.sunrise?.getOrNull(t)?.let { parseLocalIsoToEpochSec(it, utcOffsetSeconds) }-    val sunset = daily?.sunset?.getOrNull(t)?.let { parseLocalIsoToEpochSec(it, utcOffsetSeconds) }+    val zone = locationZone()+    val sunrise = daily?.sunrise?.getOrNull(t)?.let {+        zone?.let { z -> parseLocalIsoToEpochSec(it, z) } ?: parseLocalIsoToEpochSec(it, utcOffsetSeconds)+    }+    val sunset = daily?.sunset?.getOrNull(t)?.let {+        zone?.let { z -> parseLocalIsoToEpochSec(it, z) } ?: parseLocalIsoToEpochSec(it, utcOffsetSeconds)+    }      return WeatherData(         locationName = locationName,
weather/src/main/java/com/vayunmathur/weather/network/WxBundleMapper.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/network/WxBundleMapper.kt b/weather/src/main/java/com/vayunmathur/weather/network/WxBundleMapper.ktindex e8e83e5567..49f6958ad4 100644--- a/weather/src/main/java/com/vayunmathur/weather/network/WxBundleMapper.kt+++ b/weather/src/main/java/com/vayunmathur/weather/network/WxBundleMapper.kt@@ -11,11 +11,13 @@ import kotlinx.datetime.toLocalDateTime  *  * Epoch→local-ISO formatting reproduces exactly the naive-local strings  * the domain layer consumes (`yyyy-MM-dd'T'HH:mm` hourly/current/sun/moon,- * `yyyy-MM-dd` daily) using the bundle's own `utcOffset` — so- * [com.vayunmathur.weather.domain.SelectedData] string-matching,- * `MetricSeries`, the [com.vayunmathur.weather.platform.precipitationNowcast]- * nowcast, and `todayIndex` behave identically. Nothing downstream of- * `network/` changes.+ * `yyyy-MM-dd` daily) in the bundle's own IANA zone (`tz`), so each epoch+ * gets the UTC offset in force at that instant — a single fetch-time+ * `utcOffset` would shift every wall-clock string on the far side of a+ * DST transition by an hour. (Only when the zone id is unresolvable does+ * the fixed `utcOffset` remain as the converter.) Downstream inverse+ * conversions use the same zone (`ForecastResponse.timezone`), so the+ * strings round-trip exactly.  *  * Missing `pprob` passes through as-is (the server always sends the §4.6  * heuristic today). Pollen collapses to grass/tree/weed at the display@@ -35,9 +37,38 @@ private fun epochToNaiveLocal(epochSec: Long, utcOffsetSec: Int): String {     ) } +private fun epochToNaiveLocal(epochSec: Long, zone: TimeZone): String {+    // Format the wall clock in the location's IANA zone: the offset is the+    // one in force at this instant, so strings across a DST transition are+    // true local times (02:00 is skipped on spring-forward, 01:00 repeats+    // on fall-back) instead of fetch-offset-shifted ones.+    val ldt = Instant.fromEpochSeconds(epochSec).toLocalDateTime(zone)+    val d = ldt.date+    val t = ldt.time+    return String.format(+        Locale.US, "%04d-%02d-%02dT%02d:%02d",+        d.year, d.monthNumber, d.dayOfMonth, t.hour, t.minute,+    )+}++/**+ * The bundle's IANA zone, or null when it cannot be resolved (fixed-offset+ * fallback). The DTO default `tz = "UTC"` is a placeholder for "no zone+ * supplied": with a non-zero `utcOffset` it carries no zone information,+ * so the fixed offset stays the converter. A genuine UTC bundle has+ * offset 0, where both converters agree.+ */+private fun WxBundle.zoneOrNull(): TimeZone? {+    if (tz == "UTC" && utcOffset != 0) return null+    return com.vayunmathur.weather.domain.resolveTimeZone(tz)+}+  /** Daily section of the bundle mapped to the forecast shape, or null without daily data. */ private fun WxBundle.dailyResponse(off: Int): Daily? {+    val zone = zoneOrNull()+    fun local(epochSec: Long): String = zone?.let { epochToNaiveLocal(epochSec, it) }+        ?: epochToNaiveLocal(epochSec, off)     val d = daily     // Daily `start` is the first LOCAL date; entries are consecutive days.     // Add k days with date arithmetic (DST-safe; avoids 86400 assumptions).@@ -58,24 +89,27 @@ private fun WxBundle.dailyResponse(off: Int): Daily? {         temperatureMin = d.tmin,         apparentTemperatureMax = d.feelsMax,         apparentTemperatureMin = d.feelsMin,-        sunrise = d.sunrise.map { epochToNaiveLocal(it, off) },-        sunset = d.sunset.map { epochToNaiveLocal(it, off) },+        sunrise = d.sunrise.map { local(it) },+        sunset = d.sunset.map { local(it) },         daylightDuration = d.daylight.map { it.toDouble() },         sunshineDuration = d.sunshine.map { it.toDouble() },         uvIndexMax = d.uvMax,         precipitationProbabilityMax = d.pprobMax,         precipitationSum = d.precipSum,         moonPhase = d.moonPhase,-        moonrise = d.moonrise.map { it?.let { e -> epochToNaiveLocal(e, off) } },-        moonset = d.moonset.map { it?.let { e -> epochToNaiveLocal(e, off) } },+        moonrise = d.moonrise.map { it?.let { e -> local(e) } },+        moonset = d.moonset.map { it?.let { e -> local(e) } },     ) } /** `WxBundle` → [ForecastResponse] (mapped shape, cache-compatible). */ fun WxBundle.toForecastResponse(): ForecastResponse {     val off = utcOffset+    val zone = zoneOrNull()+    fun local(epochSec: Long): String = zone?.let { epochToNaiveLocal(epochSec, it) }+        ?: epochToNaiveLocal(epochSec, off)     val h = hourly     val hourlyResp = if (h == null) null else Hourly(-        time = List(h.count) { k -> epochToNaiveLocal(h.start + k * h.step, off) },+        time = List(h.count) { k -> local(h.start + k * h.step) },         temperature = h.temp,         apparentTemperature = h.feels,         relativeHumidity = h.rh,@@ -95,12 +129,12 @@ fun WxBundle.toForecastResponse(): ForecastResponse {     val dailyResp = dailyResponse(off)     val m = min15     val min15Resp = if (m == null) null else Minutely15(-        time = List(m.count) { k -> epochToNaiveLocal(m.start + k * m.step, off) },+        time = List(m.count) { k -> local(m.start + k * m.step) },         precipitation = m.precip,     )     val c = current     val currentResp = if (c == null) null else Current(-        time = epochToNaiveLocal(c.time, off),+        time = local(c.time),         temperature = c.temp,         apparentTemperature = c.feels,         relativeHumidity = c.rh,@@ -132,9 +166,10 @@ fun WxBundle.toAirQuality(): AirQualityResponse? {     val a = aq ?: return null     // Server sends current-hourestamp; the display layer parses `time` as a     // naive-local string like today's DTO.+    val zone = zoneOrNull()     return AirQualityResponse(         current = AirQualityCurrent(-            time = epochToNaiveLocal(a.time, utcOffset),+            time = zone?.let { epochToNaiveLocal(a.time, it) } ?: epochToNaiveLocal(a.time, utcOffset),             usAqi = a.usAqi,             alderPollen = a.alder,             birchPollen = a.birch,
weather/src/main/java/com/vayunmathur/weather/platform/Precipitation.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/platform/Precipitation.kt b/weather/src/main/java/com/vayunmathur/weather/platform/Precipitation.ktindex 0437898bd0..eb01066d8a 100644--- a/weather/src/main/java/com/vayunmathur/weather/platform/Precipitation.kt+++ b/weather/src/main/java/com/vayunmathur/weather/platform/Precipitation.kt@@ -11,7 +11,12 @@ import com.vayunmathur.weather.network.Minutely15  * "Rain in ~30 min", or "No rain in the next 2 hours" — or null when there  * is no usable data.  */-fun precipitationNowcast(context: Context, minutely15: Minutely15?, utcOffsetSeconds: Int): String? {+fun precipitationNowcast(+    context: Context,+    minutely15: Minutely15?,+    utcOffsetSeconds: Int,+    timeZone: kotlinx.datetime.TimeZone? = null,+): String? {     val series = minutely15 ?: return null     if (series.time.isEmpty() || series.precipitation.isEmpty()) return null @@ -20,7 +25,10 @@ fun precipitationNowcast(context: Context, minutely15: Minutely15?, utcOffsetSec      data class Slot(val epoch: Long, val precip: Double)     val slots = series.time.indices.mapNotNull { i ->-        val epoch = parseLocalIsoToEpochSec(series.time[i], utcOffsetSeconds) ?: return@mapNotNull null+        // Zone-aware when the IANA zone resolves (the offset in force at+        // that local time); the fetch-time offset is the fallback.+        val epoch = (timeZone?.let { parseLocalIsoToEpochSec(series.time[i], it) }+            ?: parseLocalIsoToEpochSec(series.time[i], utcOffsetSeconds)) ?: return@mapNotNull null         Slot(epoch, series.precipitation.getOrNull(i) ?: 0.0)     }     if (slots.isEmpty()) return null
weather/src/main/java/com/vayunmathur/weather/ui/ForecastColumn.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/ui/ForecastColumn.kt b/weather/src/main/java/com/vayunmathur/weather/ui/ForecastColumn.ktindex 9c949d3be4..16aa7e9f3b 100644--- a/weather/src/main/java/com/vayunmathur/weather/ui/ForecastColumn.kt+++ b/weather/src/main/java/com/vayunmathur/weather/ui/ForecastColumn.kt@@ -32,6 +32,7 @@ import com.vayunmathur.weather.domain.formatHourAxisLabel import com.vayunmathur.weather.domain.metricSeries import com.vayunmathur.weather.domain.metricValueFormatter import com.vayunmathur.weather.domain.localIsoToUtcIso+import com.vayunmathur.weather.domain.locationZone import com.vayunmathur.weather.domain.parseLocalIsoToEpochSec import com.vayunmathur.weather.domain.resolveConditions import com.vayunmathur.weather.platform.WeatherActions@@ -94,6 +95,14 @@ internal fun ForecastColumn(             val current = forecast.current             val daily = forecast.daily             val resolved = resolveConditions(forecast, selected)+            // IANA zone of the location: local-ISO strings convert with the+            // offset in force at that instant (DST-aware); the fetch-time+            // utc_offset_seconds is only the fallback when it doesn't resolve.+            val zone = forecast.locationZone()+            val parseIso: (String) -> Long? = { iso ->+                zone?.let { parseLocalIsoToEpochSec(iso, it) }+                    ?: parseLocalIsoToEpochSec(iso, forecast.utcOffsetSeconds)+            }              var lastSelection by remember { mutableStateOf(selected) }             LaunchedEffect(selected) { if (selected != null) lastSelection = selected }@@ -150,6 +159,7 @@ internal fun ForecastColumn(                                 scrollToIsoDate = (selected as? SelectedDateOrTime.Day)?.isoDate,                                 nowIsoHour = forecast.current?.time?.take(13)?.let { "$it:00" },                                 nowEpochSec = nowEpochSec,+                                timeZone = zone,                             )                         }                         if (daily != null) {@@ -170,14 +180,14 @@ internal fun ForecastColumn(                             current = resolved.blockCurrent,                             uvIndex = resolved.uvIndexMax,                             air = state.airQuality,-                            sunriseEpochSec = resolved.sunriseIso?.let { parseLocalIsoToEpochSec(it, forecast.utcOffsetSeconds) },-                            sunsetEpochSec = resolved.sunsetIso?.let { parseLocalIsoToEpochSec(it, forecast.utcOffsetSeconds) },+                            sunriseEpochSec = resolved.sunriseIso?.let { parseIso(it) },+                            sunsetEpochSec = resolved.sunsetIso?.let { parseIso(it) },                             precipitationMm = resolved.precipitationSum,                             precipitationNowcast = precipitationNowcast,                             daylightDurationSec = resolved.daylightDurationSec,                             moonPhase = resolved.moonPhase,-                            moonriseEpochSec = resolved.moonriseIso?.let { parseLocalIsoToEpochSec(it, forecast.utcOffsetSeconds) },-                            moonsetEpochSec = resolved.moonsetIso?.let { parseLocalIsoToEpochSec(it, forecast.utcOffsetSeconds) },+                            moonriseEpochSec = resolved.moonriseIso?.let { parseIso(it) },+                            moonsetEpochSec = resolved.moonsetIso?.let { parseIso(it) },                             onMetricSelected = { graphMetric = it },                             tempUnit = units.temperature,                             windUnit = units.wind,@@ -185,6 +195,7 @@ internal fun ForecastColumn(                             use24Hour = units.use24Hour,                             nowEpochSec = nowEpochSec,                             utcOffsetSeconds = forecast.utcOffsetSeconds,+                            timeZone = zone,                         )                     }                 }@@ -213,6 +224,7 @@ internal fun ForecastColumn(                         scrollToIsoDate = (selected as? SelectedDateOrTime.Day)?.isoDate,                         nowIsoHour = forecast.current?.time?.take(13)?.let { "$it:00" },                         nowEpochSec = nowEpochSec,+                        timeZone = zone,                     )                 }                 if (daily != null) {@@ -225,10 +237,10 @@ internal fun ForecastColumn(                     )                 }                 if (current != null && resolved != null) {-                    val sunriseEpoch = resolved.sunriseIso?.let { parseLocalIsoToEpochSec(it, forecast.utcOffsetSeconds) }-                    val sunsetEpoch = resolved.sunsetIso?.let { parseLocalIsoToEpochSec(it, forecast.utcOffsetSeconds) }-                    val moonriseEpoch = resolved.moonriseIso?.let { parseLocalIsoToEpochSec(it, forecast.utcOffsetSeconds) }-                    val moonsetEpoch = resolved.moonsetIso?.let { parseLocalIsoToEpochSec(it, forecast.utcOffsetSeconds) }+                    val sunriseEpoch = resolved.sunriseIso?.let { parseIso(it) }+                    val sunsetEpoch = resolved.sunsetIso?.let { parseIso(it) }+                    val moonriseEpoch = resolved.moonriseIso?.let { parseIso(it) }+                    val moonsetEpoch = resolved.moonsetIso?.let { parseIso(it) }                     WeatherBlocks(                         current = resolved.blockCurrent,                         uvIndex = resolved.uvIndexMax,@@ -248,6 +260,7 @@ internal fun ForecastColumn(                         use24Hour = units.use24Hour,                         nowEpochSec = nowEpochSec,                         utcOffsetSeconds = forecast.utcOffsetSeconds,+                        timeZone = zone,                     )                 }             }@@ -259,18 +272,28 @@ internal fun ForecastColumn(                 title = stringResource(gm.title),                 points = metricSeries(forecast, gm, selected),                 valueLabel = metricValueFormatter(gm, units.temperature, units.wind, units.pressure),-                timeLabel = { epoch -> formatHourAxisLabel(epoch, units.use24Hour, forecast.utcOffsetSeconds) },+                timeLabel = { epoch ->+                    val z = forecast.locationZone()+                    if (z != null) {+                        formatHourAxisLabel(epoch, units.use24Hour, z)+                    } else {+                        formatHourAxisLabel(epoch, units.use24Hour, forecast.utcOffsetSeconds)+                    }+                },                 onOpenMap = {                     // Selections are naive location-local ISO strings, but the                     // map's valid_times are UTC: convert with the forecast's-                    // offset so the map opens on the selected hour, not the+                    // zone so the map opens on the selected hour, not the                     // same wall-clock string read as UTC.                     val localIso = when (val s = selected) {                         is SelectedDateOrTime.Time -> s.isoTime                         is SelectedDateOrTime.Day -> "${s.isoDate}T00:00"                         null -> null                     }-                    val iso = localIso?.let { localIsoToUtcIso(it, forecast.utcOffsetSeconds) ?: it }+                    val z = forecast.locationZone()+                    val iso = localIso?.let {+                        (z?.let { zz -> localIsoToUtcIso(it, zz) } ?: localIsoToUtcIso(it, forecast.utcOffsetSeconds)) ?: it+                    }                     onOpenMap(gm, iso)                     graphMetric = null                 },
weather/src/main/java/com/vayunmathur/weather/ui/HomePage.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/ui/HomePage.kt b/weather/src/main/java/com/vayunmathur/weather/ui/HomePage.ktindex 5cc3d30a3c..26e8a724e7 100644--- a/weather/src/main/java/com/vayunmathur/weather/ui/HomePage.kt+++ b/weather/src/main/java/com/vayunmathur/weather/ui/HomePage.kt@@ -59,6 +59,7 @@ import com.vayunmathur.weather.domain.WeatherMetric import com.vayunmathur.weather.domain.formatHourAxisLabel import com.vayunmathur.weather.domain.metricSeries import com.vayunmathur.weather.domain.metricValueFormatter+import com.vayunmathur.weather.domain.locationZone import com.vayunmathur.weather.domain.parseLocalIsoToEpochSec import com.vayunmathur.weather.domain.resolveConditions import com.vayunmathur.weather.platform.WeatherActions@@ -123,7 +124,7 @@ fun HomePage(     // resolved here rather than inside the screen — see WeatherUiContract.     val context = LocalContext.current     val nowcast = if (selected == null && forecast != null) {-        precipitationNowcast(context, forecast.minutely15, forecast.utcOffsetSeconds)+        precipitationNowcast(context, forecast.minutely15, forecast.utcOffsetSeconds, forecast.locationZone())     } else {         null     }
weather/src/main/java/com/vayunmathur/weather/ui/components/HourlyCard.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/ui/components/HourlyCard.kt b/weather/src/main/java/com/vayunmathur/weather/ui/components/HourlyCard.ktindex 870f5a5972..cb53d8348b 100644--- a/weather/src/main/java/com/vayunmathur/weather/ui/components/HourlyCard.kt+++ b/weather/src/main/java/com/vayunmathur/weather/ui/components/HourlyCard.kt@@ -73,11 +73,14 @@ fun HourlyCard(      * out and the whole card disappears.      */     nowEpochSec: Long = System.currentTimeMillis() / 1000,+    /** The location's IANA zone when resolvable; conversions use the offset in force at each local time. */+    timeZone: TimeZone? = null, ) {     val cells = hourly.time.indices         .mapNotNull { i ->             val iso = hourly.time.getOrNull(i) ?: return@mapNotNull null-            val ts = parseLocalIsoToEpochSec(iso, utcOffsetSeconds) ?: return@mapNotNull null+            val ts = (timeZone?.let { parseLocalIsoToEpochSec(iso, it) }+                ?: parseLocalIsoToEpochSec(iso, utcOffsetSeconds)) ?: return@mapNotNull null             HourCell(                 iso = iso,                 epochSec = ts,@@ -114,8 +117,14 @@ fun HourlyCard(                     val cell = cells[index]                     val isNow = cell.iso == nowIsoHour                     HourlyItem(-                        time = if (isNow) stringResource(R.string.now) else formatStripHour(cell.epochSec, use24Hour, utcOffsetSeconds),-                        dayLabel = formatDayLabel(cell.epochSec, nowEpochSec, utcOffsetSeconds),+                        time = if (isNow) {+                            stringResource(R.string.now)+                        } else if (timeZone != null) {+                            formatStripHour(cell.epochSec, use24Hour, timeZone)+                        } else {+                            formatStripHour(cell.epochSec, use24Hour, utcOffsetSeconds)+                        },+                        dayLabel = formatDayLabel(cell.epochSec, nowEpochSec, utcOffsetSeconds, timeZone),                         precipitationProbability = cell.precip,                         temperature = cell.temperature,                         isNow = isNow,@@ -226,11 +235,14 @@ private data class HourCell( )  @Composable-private fun formatDayLabel(epochSec: Long, nowEpochSec: Long, utcOffsetSeconds: Int): String {+private fun formatDayLabel(epochSec: Long, nowEpochSec: Long, utcOffsetSeconds: Int, timeZone: TimeZone? = null): String {     // Same shift-then-read-in-UTC as domain localTimeAt: Instant.toLocalDateTime(UtcOffset)-    // is internal in this kotlinx-datetime version.-    val date = Instant.fromEpochSeconds(epochSec + utcOffsetSeconds).toLocalDateTime(TimeZone.UTC).date-    val today = Instant.fromEpochSeconds(nowEpochSec + utcOffsetSeconds).toLocalDateTime(TimeZone.UTC).date+    // is internal in this kotlinx-datetime version. With an IANA zone, the+    // date is read directly in that zone (DST-aware).+    val date = timeZone?.let { Instant.fromEpochSeconds(epochSec).toLocalDateTime(it).date }+        ?: Instant.fromEpochSeconds(epochSec + utcOffsetSeconds).toLocalDateTime(TimeZone.UTC).date+    val today = timeZone?.let { Instant.fromEpochSeconds(nowEpochSec).toLocalDateTime(it).date }+        ?: Instant.fromEpochSeconds(nowEpochSec + utcOffsetSeconds).toLocalDateTime(TimeZone.UTC).date     val tomorrow = today.plus(1, DateTimeUnit.DAY)     return when (date) {         today -> stringResource(R.string.today_short)
weather/src/main/java/com/vayunmathur/weather/ui/components/WeatherBlocks.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/ui/components/WeatherBlocks.kt b/weather/src/main/java/com/vayunmathur/weather/ui/components/WeatherBlocks.ktindex 3cdec3f1f6..99f36c5cdf 100644--- a/weather/src/main/java/com/vayunmathur/weather/ui/components/WeatherBlocks.kt+++ b/weather/src/main/java/com/vayunmathur/weather/ui/components/WeatherBlocks.kt@@ -65,6 +65,8 @@ fun WeatherBlocks(     nowEpochSec: Long = System.currentTimeMillis() / 1000,     /** `utc_offset_seconds` for the forecast location; null renders times in the device zone. */     utcOffsetSeconds: Int? = null,+    /** The location's IANA zone when resolvable; takes precedence over [utcOffsetSeconds] (DST-aware). */+    timeZone: kotlinx.datetime.TimeZone? = null, ) {     LazyVerticalGrid(         columns = GridCells.Adaptive(minSize = 140.dp),@@ -89,8 +91,8 @@ fun WeatherBlocks(         item { Graphable({ onMetricSelected(WeatherMetric.CloudCover) }) { CloudCoverBlock(current = current) } }         item { Graphable({ onMetricSelected(WeatherMetric.Pressure) }) { PressureBlock(current = current, pressureUnit = pressureUnit) } }         item { Graphable({ onMetricSelected(WeatherMetric.Visibility) }) { VisibilityBlock(current = current, useMiles = windUnit == WindUnit.Mph) } }-        item { SunBlock(sunriseEpochSec = sunriseEpochSec, sunsetEpochSec = sunsetEpochSec, use24Hour = use24Hour, daylightDurationSec = daylightDurationSec, nowEpochSec = nowEpochSec, utcOffsetSeconds = utcOffsetSeconds) }-        item { MoonBlock(moonPhase = moonPhase, moonriseEpochSec = moonriseEpochSec, moonsetEpochSec = moonsetEpochSec, use24Hour = use24Hour, nowEpochSec = nowEpochSec, utcOffsetSeconds = utcOffsetSeconds) }+        item { SunBlock(sunriseEpochSec = sunriseEpochSec, sunsetEpochSec = sunsetEpochSec, use24Hour = use24Hour, daylightDurationSec = daylightDurationSec, nowEpochSec = nowEpochSec, utcOffsetSeconds = utcOffsetSeconds, timeZone = timeZone) }+        item { MoonBlock(moonPhase = moonPhase, moonriseEpochSec = moonriseEpochSec, moonsetEpochSec = moonsetEpochSec, use24Hour = use24Hour, nowEpochSec = nowEpochSec, utcOffsetSeconds = utcOffsetSeconds, timeZone = timeZone) }         item { AirQualityBlock(air = air) }         item { PollenBlock(air = air) }     }
weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/MoonBlock.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/MoonBlock.kt b/weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/MoonBlock.ktindex ea51ec0497..c08f9efce5 100644--- a/weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/MoonBlock.kt+++ b/weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/MoonBlock.kt@@ -54,6 +54,8 @@ fun MoonBlock(     nowEpochSec: Long = System.currentTimeMillis() / 1000,     /** `utc_offset_seconds` for the forecast location; null renders in the device zone. */     utcOffsetSeconds: Int? = null,+    /** The location's IANA zone when resolvable; takes precedence over [utcOffsetSeconds] (DST-aware). */+    timeZone: kotlinx.datetime.TimeZone? = null, ) {     SquareBlock {         Box(Modifier.align(Alignment.TopStart)) {@@ -109,13 +111,15 @@ fun MoonBlock(                     verticalArrangement = Arrangement.spacedBy(3.dp),                 ) {                     RiseSetTimeRow(-                        text = moonriseEpochSec?.let { formatClockTime(it, use24Hour, utcOffsetSeconds) }-                            ?: stringResource(R.string.weather_no_data),+                        text = moonriseEpochSec?.let {+                            if (timeZone != null) formatClockTime(it, use24Hour, timeZone) else formatClockTime(it, use24Hour, utcOffsetSeconds)+                        } ?: stringResource(R.string.weather_no_data),                         icon = { m, c -> IconKeyboardArrowUp(m, c) },                     )                     RiseSetTimeRow(-                        text = moonsetEpochSec?.let { formatClockTime(it, use24Hour, utcOffsetSeconds) }-                            ?: stringResource(R.string.weather_no_data),+                        text = moonsetEpochSec?.let {+                            if (timeZone != null) formatClockTime(it, use24Hour, timeZone) else formatClockTime(it, use24Hour, utcOffsetSeconds)+                        } ?: stringResource(R.string.weather_no_data),                         icon = { m, c -> IconKeyboardArrowDown(m, c) },                     )                     if (moonPhase != null) {
weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/SunBlock.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/SunBlock.kt b/weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/SunBlock.ktindex 85ee0e97b4..15b4dddf90 100644--- a/weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/SunBlock.kt+++ b/weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/SunBlock.kt@@ -42,6 +42,8 @@ fun SunBlock(     nowEpochSec: Long = System.currentTimeMillis() / 1000,     /** `utc_offset_seconds` for the forecast location; null renders in the device zone. */     utcOffsetSeconds: Int? = null,+    /** The location's IANA zone when resolvable; takes precedence over [utcOffsetSeconds] (DST-aware). */+    timeZone: kotlinx.datetime.TimeZone? = null, ) {     SquareBlock {         Box(Modifier.align(Alignment.TopStart)) {@@ -94,11 +96,15 @@ fun SunBlock(                     verticalArrangement = Arrangement.spacedBy(3.dp),                 ) {                     RiseSetTimeRow(-                        text = sunriseEpochSec?.let { formatClockTime(it, use24Hour, utcOffsetSeconds) } ?: "—",+                        text = sunriseEpochSec?.let {+                            if (timeZone != null) formatClockTime(it, use24Hour, timeZone) else formatClockTime(it, use24Hour, utcOffsetSeconds)+                        } ?: "—",                         icon = { m, c -> IconSunny(m, c) },                     )                     RiseSetTimeRow(-                        text = sunsetEpochSec?.let { formatClockTime(it, use24Hour, utcOffsetSeconds) } ?: "—",+                        text = sunsetEpochSec?.let {+                            if (timeZone != null) formatClockTime(it, use24Hour, timeZone) else formatClockTime(it, use24Hour, utcOffsetSeconds)+                        } ?: "—",                         icon = { m, c -> IconClearNight(m, c) },                     )                     if (daylightDurationSec != null) {
weather/src/test/java/com/vayunmathur/weather/network/WxBundleDstTest.kt
diff --git a/weather/src/test/java/com/vayunmathur/weather/network/WxBundleDstTest.kt b/weather/src/test/java/com/vayunmathur/weather/network/WxBundleDstTest.ktnew file mode 100644index 0000000000..b6258df4b8--- /dev/null+++ b/weather/src/test/java/com/vayunmathur/weather/network/WxBundleDstTest.kt@@ -0,0 +1,104 @@+package com.vayunmathur.weather.network++import com.vayunmathur.weather.domain.formatClockTime+import com.vayunmathur.weather.domain.parseLocalIsoToEpochSec+import kotlinx.datetime.TimeZone+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotNull+import kotlin.time.Instant++/**+ * Regression tests for the DST wall-clock shift in the bundle mapper.+ *+ * The bundle carries one `utc_offset` (the offset at fetch time) plus the+ * IANA `tz` name. Converting every epoch with that single fixed offset+ * renders wall-clock strings on the far side of a DST transition one hour+ * early/late: with a fetch on 2026-03-06 in New York (EST, UTC-5), the+ * true 07:12 EDT sunrise on 2026-03-09 (11:12Z) came out as "06:12", and+ * the hourly strip showed a nonexistent 2 AM on spring-forward night.+ * Conversions must go through the IANA zone, per epoch.+ */+class WxBundleDstTest {++    private val ny = TimeZone.of("America/New_York")++    private fun epoch(isoZ: String): Long = Instant.parse(isoZ).epochSeconds++    // Fetch instant: 2026-03-06T17:00Z = 12:00 EST in New York.+    private fun bundle() = WxBundle(+        lat = 40.71,+        lon = -74.01,+        tz = "America/New_York",+        tzAbbr = "EST",+        utcOffset = -5 * 3600,+        current = WxCurrent(+            time = epoch("2026-03-06T17:00:00Z"), temp = 5.0, feels = 3.0, rh = 60,+            dew = 0.0, code = 1, windSpd = 4.0, windDir = 90,+            pres = 1015.0, vis = 20000.0, cloud = 10, gust = 8.0, day = 1,+        ),+        hourly = WxHourly(+            // Spring-forward night: 01:00 EST, then 03:00 EDT (02:00 never exists).+            start = epoch("2026-03-08T06:00:00Z"), step = 3600, count = 3,+            temp = listOf(4.0, 4.5, 5.0), feels = listOf(2.0, 2.5, 3.0),+            rh = listOf(60, 61, 62), dew = listOf(0.0, 0.1, 0.2),+            code = listOf(1, 1, 1), pprob = listOf(5, 5, 5),+            precip = listOf(0.0, 0.0, 0.0), windSpd = listOf(4.0, 4.0, 4.0),+            windDir = listOf(90, 90, 90), pres = listOf(1015.0, 1015.0, 1015.0),+            vis = listOf(20000.0, 20000.0, 20000.0), uv = listOf(0.0, 0.0, 0.0),+            cloud = listOf(10, 10, 10), gust = listOf(8.0, 8.0, 8.0),+            day = listOf(0, 0, 0),+        ),+        daily = WxDaily(+            start = "2026-03-06", count = 4,+            code = listOf(1, 1, 1, 1), tmax = listOf(8.0, 9.0, 10.0, 11.0),+            tmin = listOf(0.0, 1.0, 2.0, 3.0), feelsMax = listOf(7.0, 8.0, 9.0, 10.0),+            feelsMin = listOf(-1.0, 0.0, 1.0, 2.0),+            // 2026-03-09 sunrise in New York: 07:12 EDT = 11:12Z.+            sunrise = listOf(+                epoch("2026-03-06T11:55:00Z"), epoch("2026-03-07T11:53:00Z"),+                epoch("2026-03-08T11:51:00Z"), epoch("2026-03-09T11:12:00Z"),+            ),+            sunset = listOf(+                epoch("2026-03-06T22:55:00Z"), epoch("2026-03-07T22:56:00Z"),+                epoch("2026-03-08T23:57:00Z"), epoch("2026-03-09T23:58:00Z"),+            ),+            daylight = listOf(39600, 39780, 39960, 38760), sunshine = listOf(10000, 10000, 10000, 10000),+            uvMax = listOf(2.0, 2.0, 2.0, 2.0), pprobMax = listOf(5, 5, 5, 5),+            precipSum = listOf(0.0, 0.0, 0.0, 0.0), moonPhase = listOf(0.4, 0.43, 0.46, 0.5),+            moonrise = listOf(null, null, null, null), moonset = listOf(null, null, null, null),+        ),+    )++    @Test+    fun dailySunriseAfterSpringForward_usesPostTransitionOffset() {+        val d = assertNotNull(bundle().toForecastResponse().daily)+        assertEquals("2026-03-06", d.time[0])+        // Pre-transition day keeps EST: 11:55Z = 06:55 EST.+        assertEquals("2026-03-06T06:55", d.sunrise[0])+        // Post-transition day must use EDT: 11:12Z = 07:12 EDT, not 06:12.+        assertEquals("2026-03-09T07:12", d.sunrise[3])+        assertEquals("2026-03-09T19:58", d.sunset[3])+    }++    @Test+    fun hourlyAcrossSpringForward_skipsNonexistentHour() {+        val h = assertNotNull(bundle().toForecastResponse().hourly)+        assertEquals(+            listOf("2026-03-08T01:00", "2026-03-08T03:00", "2026-03-08T04:00"),+            h.time,+        )+    }++    @Test+    fun mappedLocalIso_roundTripsThroughZone() {+        val sunriseEpoch = epoch("2026-03-09T11:12:00Z")+        assertEquals(sunriseEpoch, parseLocalIsoToEpochSec("2026-03-09T07:12", ny))+        assertEquals("07:12", formatClockTime(sunriseEpoch, true, ny))+        // Fall-back side: 2026-11-02 is EST again; 12:12Z = 07:12 EST.+        assertEquals(+            epoch("2026-11-02T12:12:00Z"),+            parseLocalIsoToEpochSec("2026-11-02T07:12", ny),+        )+    }+}