Skip to content

✨ Add day/night weather icons#29

Merged
Tairesh merged 3 commits intomainfrom
day-night-icons
May 5, 2026
Merged

✨ Add day/night weather icons#29
Tairesh merged 3 commits intomainfrom
day-night-icons

Conversation

@Tairesh
Copy link
Copy Markdown
Owner

@Tairesh Tairesh commented May 5, 2026

Summary

Render distinct ASCII art and emoji for Clear and PartlyCloudy conditions when it is night-time at the queried location, populated from each provider's API where available and falling back to a local solar-altitude calculation otherwise.

  • New Weather.is_day: Option<bool> (also surfaced in JSON output); location_name, latitude, longitude bundled into a single Weather.location: Location field.
  • New src/weather/sun.rs — pure NOAA low-precision solar altitude function (no I/O, no API key).
  • New src/weather/enrich.rs — post-provider wrapper that fills missing is_day (from sun) and uv_index (from OpenUV); single integration point in App::fetch_with_fallback so live mode picks it up automatically.
  • Native is_day for: open_meteo (is_day query var), weather_api (is_day field), yr (_day/_night suffix on symbol_code), open_weather_map (d/n suffix on icon code), weather_bit (pod field).
  • Solar-altitude fallback for: tomorrow_io and world_weather_online.
  • world_weather_online fix: add includelocation=yes, parse nearest_area for coordinates, share name shortener with tomorrow_io, trim trailing space in description.
  • Lift OpenUV calls out of three providers (open_meteo, open_weather_map, yr) into the shared enrich wrapper.

Test Plan

  • just check passes (fmt, build, 141 tests, clippy pedantic)
  • New unit tests: solar altitude (14 cases — polar/equator/antimeridian/mid-latitude/leap and non-leap years), enrich wrapper (5), shorten_location_name (5), icon module (4), formatter night/day rendering (2), per-provider parsing (6+)
  • New WWO fixture at tests/data/wwo_response.json with parsing test (file had zero parsing tests before)
  • Smoke-tested live: open_meteo (Tokyo/London), world_weather_online (London is_day: false, Tokyo is_day: true), tomorrow_io (Batumi shortener still works after refactor)
  • Manual verification by reviewer with their own API keys for paid providers

- Add `is_day` to Weather and bundle location_name/lat/lon into Location
- Add night-variant ASCII art and emoji for Clear and PartlyCloudy
- Populate `is_day` natively from open_meteo, weather_api, yr,
  open_weather_map, and weather_bit
- Add NOAA solar-altitude fallback (`weather/sun.rs`) for tomorrow_io
  and world_weather_online
- Introduce `weather/enrich.rs` post-provider wrapper that fills missing
  `is_day` and `uv_index`; lifts OpenUV calls out of individual providers
- Fix world_weather_online: add `includelocation=yes`, parse `nearest_area`
  for coordinates, share name shortener with tomorrow_io, trim trailing
  space in description
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces day/night awareness by adding an "is_day" field to the Weather model and updating weather providers to populate it. It also replaces the "location_name" string with a structured Location object. A new enrich module is added to calculate daytime status using solar altitude algorithms in sun.rs or extract it from various weather providers. Display logic in formatter.rs and icons.rs now uses this information to show appropriate icons and emojis for night time. A potential issue was identified in the solar altitude calculation where floating-point precision could lead to NaN results in asin(), and a fix was suggested.

Comment thread src/weather/sun.rs Outdated
Tairesh added 2 commits May 6, 2026 03:42
Floating-point rounding can push sin_alt slightly outside [-1, 1],
making asin() return NaN at poles or exact solstice/equinox times.
@Tairesh Tairesh merged commit 3e141c8 into main May 5, 2026
3 checks passed
@Tairesh Tairesh deleted the day-night-icons branch May 5, 2026 20:48
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