Repository navigation
fix: isDaytime returns wrong value near UTC midnight - #79
Merged
Merged
Conversation
isDaytime compared date against the sunrise/sunset window anchored to date's UTC calendar day. When the local solar day straddles UTC midnight (evenings west of Greenwich, mornings east of it), the window containing date belongs to the previous or next UTC day, so the sun could be up while isDaytime returned false. Check the stored window first, then fall back to the windows computed for the adjacent UTC days, skipping days with no sunrise/sunset near the polar circles. Boundary semantics (>= sunrise, < sunset) are unchanged. Adds regression tests pinning both sides of the boundary in each direction (Minneapolis evening, Tokyo morning). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PYPBCzQiXBvadC3y6Ae6FH
ceeK
marked this pull request as ready for review
August 30, 2026 22:11
This was referenced Aug 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
The sun can be up while
isDaytimesaysfalse. Happens every evening west of Greenwich, every morning east of it. Two forks independently patched this. Fixed here + regression tests.The bug, in one example
isDaytimeonly checks the sunrise→sunset window of the UTC calendar day (June 16: sunrise 10:26 UTC → sunset 02:02 UTC June 17).false. Wrong. 🌑Mirror image in Tokyo: 08:30 JST is still yesterday in UTC → morning sun reads as night.
The fix
The correct window always exists — it just belongs to a neighbouring UTC day. So:
sunrise/sunsetwindow first (the common case, zero extra work).date − 24handdate + 24hand check those.Boundary semantics unchanged:
>= sunriseis day,< sunsetflips to night. Polar day/night behaviour unchanged (that's #59, separate).Tests
4 new tests pin both sides of the boundary in both directions:
swift test: 14/14 pass (all existing tests untouched and green).Related
Closes the same defect reported via #44/#45/#48 (this version is nil-safe and adds no API). Root-cause option (anchoring
calculate()to the solar day instead of the UTC day) is a behaviour-breaking change — worth considering for a major version, not this PR.