From f330a3320245c78b5110980b61d6d821ffc0bcb2 Mon Sep 17 00:00:00 2001 From: Matthew Fisher <17348508+GaijinSystems@users.noreply.github.com> Date: Tue, 13 Oct 2026 08:33:36 -0500 Subject: [PATCH] NWS: keep today in daily forecast after its daytime period ends NWS drops a day's daytime period once it has passed, so in the evening the forecast starts with "Tonight". The daily list was built from daytime periods only, so today disappeared from it and daily[0] became tomorrow. Tonight's hourly icons then fell back to day icons, and the sun/moon blocks and max/min showed tomorrow's values. Group periods by local day and use the daytime period, falling back to the night period for a day without one (today or later only, so a stale forecast doesn't bring back yesterday). Fixes #1199 --- .../mapper/weather/sources/nws/NwsJsonMapper.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/pranshulgg/weather_master_app/data/local/mapper/weather/sources/nws/NwsJsonMapper.kt b/app/src/main/java/com/pranshulgg/weather_master_app/data/local/mapper/weather/sources/nws/NwsJsonMapper.kt index 38e87632b..70374f3b3 100644 --- a/app/src/main/java/com/pranshulgg/weather_master_app/data/local/mapper/weather/sources/nws/NwsJsonMapper.kt +++ b/app/src/main/java/com/pranshulgg/weather_master_app/data/local/mapper/weather/sources/nws/NwsJsonMapper.kt @@ -19,6 +19,7 @@ import com.pranshulgg.weather_master_app.core.network.sources.weather.nws.json.N import com.pranshulgg.weather_master_app.core.network.sources.weather.nws.json.bundle.NwsWeatherJsonBundle import com.pranshulgg.weather_master_app.core.utils.extensions.DateTimeExtensions.iso8601TimestampToMilliseconds import com.pranshulgg.weather_master_app.core.utils.extensions.DateTimeExtensions.normalizeToDay +import com.pranshulgg.weather_master_app.core.utils.formatters.getCurrentTimeFor import com.pranshulgg.weather_master_app.core.utils.weather.astronomy.getMoonTimings import com.pranshulgg.weather_master_app.core.utils.weather.astronomy.getSunTimings import com.pranshulgg.weather_master_app.core.utils.weather.calculations.computeApparentTemperature @@ -112,6 +113,19 @@ fun NwsWeatherJsonBundle.toDomain(location: Location): Weather { location.longitude ) + /** + * NWS drops a day's daytime period once it has passed, so in the evening the forecast starts + * with "Tonight". Use the night period for a day that has no daytime period, otherwise today + * is missing from daily (and hourly day/night icons, sun and moon blocks use the wrong day) + */ + val today = getCurrentTimeFor(zoneId).normalizeToDay(zoneId) + + val dailyPeriods = daily.periods + .groupBy { it.startTime.iso8601TimestampToMilliseconds().normalizeToDay(zoneId) } + .mapNotNull { (day, periods) -> + periods.firstOrNull { it.isDayTime } ?: periods.first().takeIf { day >= today } + } + return Weather( location = location, current = WeatherCurrent( @@ -159,7 +173,7 @@ fun NwsWeatherJsonBundle.toDomain(location: Location): Weather { dewPoint = it.dewPoint.value ) }, - daily = daily.periods.filter { it.isDayTime }.map { item -> + daily = dailyPeriods.map { item -> val index = daily.periods.indexOf(item)