Sun position and timing calculations based on NOAA solar equations.
$ npm install @litejs/sunimport { sun } from "@litejs/sun"
let data = sun(59.437, 24.753, "2025-03-20T12:00:00Z")
console.log("Sunrise:", data.rise.time, "Sunset:", data.set.time)
// Sunrise: 2025-03-20T04:22:24.000Z Sunset: 2025-03-20T16:35:43.000Z
console.log("Azimuth:", data.azimuth, "Elevation:", data.el)
// Azimuth: 206.16 Elevation: 28.01Returns an object with the following properties:
| Property | Description |
|---|---|
time |
Date object for the given time |
decl |
Solar declination (degrees) |
dur |
Daylight duration (minutes) |
el |
Solar elevation with refraction (degrees) |
elTrue |
Solar elevation without refraction (degrees) |
eqTime |
Equation of time (minutes) |
hourAngle |
Solar hour angle (degrees) |
azimuth |
Solar azimuth (degrees, lazy) |
dist |
Distance to sun in AU (lazy) |
rightAsc |
Right ascension (degrees, lazy) |
noon |
Solar noon data (lazy) |
rise |
Sunrise data (lazy) |
set |
Sunset data (lazy) |
The noon, rise, and set getters return objects with the same structure, with time refined to the exact event.
During polar day or polar night, rise and set find the nearest event, which may be days or months away.
Returns null only at extreme latitudes (e.g., the poles) where no sunrise or sunset occurs within a year.
Follow Coding Style Guide,
run tests npm install; npm test.
Copyright (c) 2025 Lauri Rooden <[email protected]>
MIT License | GitHub repo | npm package | Buy Me A Tea