Skip to content

NOAACalculator, MeeusCalculator: don't miss zmanim the sun only just reaches - #295

Merged
KosherJava merged 1 commit into
KosherJava:masterfrom
dickermoshe:meeus-noaa-rise-set-fallback
Oct 22, 2026
Merged

KosherJava merged 1 commit into
KosherJava:masterfrom
dickermoshe:meeus-noaa-rise-set-fallback

Conversation

@dickermoshe

@dickermoshe dickermoshe commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

On some days the sun only just reaches an angle like 16.1° or 18° below the horizon, right around midnight. NOAACalculator and MeeusCalculator return no zman (NaN) on those days, even though the zman exists.

Why

Both calculators start from the sun's declination at noon. If the angle is out of reach at that declination, they stop and return NaN. But the declination changes during the day, by up to about 0.2° in 12 hours. So near the start and end of the season when a zman stops existing, the sun can reach the angle around midnight even though noon's figures say it can't.

Examples (UTC):

Location Date Zman Before After
London 2024-06-03 16.1° alos NaN 00:10
London 2024-07-20 18° tzais NaN 23:52
75.5°N 2093-04-22 sunrise NaN 00:13

This isn't a polar edge case. For London, Manchester, Edinburgh, Copenhagen, Stockholm, Toronto and Montreal, every day from 2024 to 2030, at alos/tzais angles from 16.1° to 26°, each calculator was missing 234 zmanim. It's a few days every year, on the same dates.

Change

When the first pass finds the angle out of reach, it now tries once more using the sun's declination at the solar midnight next to the event. That's the night before for sunrise and the night after for sunset, when the sun is lowest. If the angle is reachable there, the existing passes continue as usual. Nothing else changes.

Testing

I checked results against an independent search that steps through the half day minute by minute, using each calculator's own sun-position model:

  • Seven cities, 2024–2030: all 468 missing zmanim now come back, and no other result changed.
  • 300,000 random cases up to 66.5° latitude: 148 missing zmanim recovered per calculator, and no other result changed.
  • Accuracy: the recovered times are as accurate as each calculator's normal results, within 16 seconds for NOAA and 3 seconds for Meeus.
  • New tests: NOAACalculatorTest and MeeusCalculatorTest each get a test covering the three examples above.

Not covered

  • The reverse case. On a night when the sun misses the angle by a tiny amount, the calculators can still return a time. In the city data above this happened about once in 24,000 results for NOAA and once in 100,000 for Meeus. Each time, the sun came within 0.004° of the angle, which is smaller than the calculators' own position error. So I left it alone.
  • Above about 80° latitude, a recovered time can be off by several minutes. The fixed number of passes already produces errors like that at those latitudes.
  • SPA tests on master. Master currently fails 10 SPACalculatorTest tests since 7cab372. This PR doesn't touch SPA.

@dickermoshe
dickermoshe force-pushed the meeus-noaa-rise-set-fallback branch from 481e6d7 to 7d5dfb0 Compare October 22, 2026 03:26
@dickermoshe dickermoshe changed the title NOAACalculator, MeeusCalculator: confirm rise/set results on borderline days NOAACalculator, MeeusCalculator: check solar midnight before reporting no event Oct 22, 2026
@dickermoshe
dickermoshe force-pushed the meeus-noaa-rise-set-fallback branch from 7d5dfb0 to b69f97e Compare October 22, 2026 03:27
@dickermoshe dickermoshe changed the title NOAACalculator, MeeusCalculator: check solar midnight before reporting no event NOAACalculator, MeeusCalculator: don't miss zmanim the sun only just reaches Oct 22, 2026
…g no event

The first pass uses the solar declination at noon. The declination moves up
to about 0.2 degrees in half a day, so on days when the Sun only just reaches
the zenith near midnight, noon's declination puts it out of reach and the
calculation returned NaN. When the first pass finds the zenith out of reach,
it is now retried with the declination and equation of time at the solar
midnight next to the event before giving up. Every other result is unchanged.
@dickermoshe
dickermoshe force-pushed the meeus-noaa-rise-set-fallback branch from b69f97e to ac7b4fb Compare October 22, 2026 03:33
@dickermoshe
dickermoshe marked this pull request as ready for review October 22, 2026 03:33
@KosherJava
KosherJava merged commit 0bd7893 into KosherJava:master Oct 22, 2026
2 of 3 checks passed
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.

2 participants