nrel_spa 1.2.0
nrel_spa: ^1.2.0 copied to clipboard
NREL Solar Position Algorithm for Dart and Flutter. Calculates solar zenith, azimuth, sunrise, sunset, and solar noon for any location and time. Pure Dart, zero dependencies, ±0.0003° accuracy.
1.2.0 #
Added #
-
getSpaandcalcSpaaccept a'YYYY-MM-DD'string as well as aDateTime, withtoSpaInstantexported.The two functions answer two different kinds of question from one argument, and they do not want the same input. Instantaneous position (
zenith,azimuth,incidence) depends on the exact moment, and aDateTimeis exactly right. Rise, transit and set depend only on the calendar day — verified: holding the date and varying the hour from 00 to 23 leavessunrise,solarNoonandsunsetidentical to six decimal places.For that second case a bare
DateTimewas a trap.toUtc()deliberately discards the author's frame in favour of the instant, which is right for position and wrong for a day:DateTime(2026, 8, 22)is2026-08-21T15:00Zin Tokyo, so a Tokyo caller silently received the previous day's sunrise. Measured at 59 seconds out for New York (5.205775 against 5.222164 hours).A
'YYYY-MM-DD'string names the day outright, anchored at UTC noon — the furthest point from either day boundary. It returns the identical value on every host, and matches the TypeScriptnrel-spa2.2.0 output exactly, which a test now asserts.
Changed #
- Nothing on the
DateTimepath; it behaves exactly as in 1.1.0. A test guards that instantaneous position still varies with the hour, so a future change cannot normalise the instant away.
Notes on upgrading #
Purely additive. If you use this package to ask about a day rather than a moment, prefer the string form:
getSpa('2026-08-22', lat, lng, tz); // unambiguous
getSpa(DateTime(2026, 8, 22), lat, lng, tz); // depends on where the machine is
Verified downstream: pray_calc_dart 1.2.0's full suite, including its 282-vector cross-language parity fixture, passes unchanged against this release.
1.1.0 #
- The NREL "no such event" sentinel no longer crosses the public API. The reference
implementation writes
-99999intosrha,ssha,sta,suntransit,sunriseandsunsetwhen the sun does not cross the horizon, and that value was handed to callers unchanged. Because it is a finite number it passed everyisFiniteguard downstream and rendered as a real clock time.getSpanow returnsdouble.nanfor events that do not occur. Two leak paths closed: the raw result fields, and_adjustForCustomAngle, which offsets from solar transit and so produced plausible-looking values such as-100001.38. solarNoonsurvives polar day and polar night. The sun crosses the local meridian every day everywhere on Earth, so solar transit is always defined, but the reference blanks it alongside the genuinely absent sunrise and sunset. It is now recovered from the equation of time. Where the reference produces a transit that value passes through untouched, so no existing result moves.lib/src/spa.dartremains a faithful port of the reference, sentinel included; the conversion happens at the API boundary.