SunCalc 2.0 is a precision-focused rewrite that matches the accuracy and conventions of timeanddate.com and the U.S. Naval Observatory. It now ships as a modern ES module with TypeScript declarations, plus a bundled CommonJS/UMD build for legacy require() and <script> use.
Dramatically improved accuracy ⚡
Every function was rebuilt on higher-order astronomical models (Jean Meeus' Astronomical Algorithms) and validated against JPL Horizons and the USNO. Typical errors versus v1:
| v1 | v2 | ||
|---|---|---|---|
| Sun position | ~0.43° | ~0.08° | ~5× better |
| Sun rise/set times | ~75 s | ~15 s | ~5× better |
| Moon position | ~1.2° | ~0.09° | ~14× better |
| Moon rise/set times | ~5 min | ~15 s | ~20× better |
| Moon distance | ~3500 km | ~20 km | ~150× better |
Sun and moon times are now accurate to ~15 seconds — at the floor of what the USNO's whole-minute reference data can even measure.
Breaking changes ⚠️
- ESM-first. The source is now a native ES module —
import * as SunCalc from 'suncalc'. A bundled UMD build still supportsrequire('suncalc')and direct<script>tags (globalSunCalc, also on unpkg / jsDelivr). - Angles in degrees. Every angle in and out — altitude, azimuth, illumination angle, parallactic angle — is in degrees, not radians.
- North-based azimuth. Azimuth is measured clockwise from north:
0= N,90= E,180= S,270= W (v1 measured from south). - Apparent altitude.
getPosition/getMoonPositionnow return the apparent (atmospheric-refraction-corrected) altitude, so positions near the horizon match what you actually observe. - Dates are UTC instants. Inputs and outputs are absolute moments in time; no local-timezone conversion is applied.
getTimesresolves the input date's solar day regardless of the time-of-day you pass (in v1 you had to pass noon to avoid off-by-one-day surprises). getMoonTimesscans the UTC day of the given date; theinUTCargument has been removed. For a local-civil-day window, pass a date set to local midnight.- Missing events are
null. When an event doesn't occur (e.g. the sun never rises at high latitudes), its time isnullrather than anInvalid Date, andgetTimessetsalwaysUp/alwaysDownaccordingly.
Other changes
- Added a
waxingflag togetMoonIllumination. - Bundled hand-written TypeScript declarations (
index.d.ts).