Skip to content

Fix stale day/night weather glyph (derive at render time) - #8

Merged
shining-cat merged 1 commit into
mainfrom
fix/day-night-render-derivation
Aug 4, 2026
Merged

Fix stale day/night weather glyph (derive at render time)#8
shining-cat merged 1 commit into
mainfrom
fix/day-night-render-derivation

Conversation

@shining-cat

Copy link
Copy Markdown
Owner

Problem

The weather glyph showed a moon crescent during the day (observed at 13:44). nowIsDay was baked once at fetch time from Open-Meteo's is_day, cached as a boolean, and merely read back on every minute-tick redraw. Weather refreshes at most every 30 min (network-constrained, Doze-deferrable), so the day/night flag froze between fetches — the moon persisted into daytime and vice-versa.

Fix

Fetch and cache today's sunrise/sunset, and derive nowIsDay at render time from the current clock instead of trusting the stale cached boolean. Self-corrects every minute-tick even with zero daytime fetches (Doze-proof).

  • daily=weather_code,sunrise,sunset on the fetch → DailyDto (sunrise/sunset defaulted to emptyList(), so a custom endpoint that omits them still parses) → carried on WeatherSnapshot → cached with two new nullable string keys (remove-on-null; no migration — old caches read null).
  • New pure DayNightResolver.isDay(now, sunriseIso, sunsetIso, fallback) — time-of-day compare over [sunrise, sunset); falls back to the fetch-time is_day when times are absent or unparseable.
  • WidgetStateResolver applies it using its already-injected now lambda, copy()-correcting the snapshot. DotGrid is untouched — the renderer stays a dumb consumer.

Time-of-day comparison (not date-matched) is immune to a missed-midnight cache and is plenty precise for a sun-vs-moon glyph.

Tests

TDD, JUnit5 + injected-lambda clock + hand fakes:

  • new DayNightResolverTest (9) — window, inclusive-sunrise/exclusive-sunset boundaries, null/unparseable fallback, and the 13:44-moon regression.
  • WidgetStateResolverTest — stale is_day=false snapshot corrected to day at render; fallback kept when sunrise/sunset absent.
  • WeatherMapperTest, ForecastDtoParseTest, DataStorePersistenceTest extended for sunrise/sunset mapping, parsing (incl. omitted), and cache round-trip (incl. null).

./gradlew test spotlessCheck — all green.

🤖 Generated with Claude Code

… at render time

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@shining-cat
shining-cat merged commit de1725d into main Aug 4, 2026
4 checks passed
@shining-cat
shining-cat deleted the fix/day-night-render-derivation branch August 4, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant