Status: Development
⚠️
Calculate the position of the sun for a specific date, time and location. Calculate sunrise and sunset
Sun Position is a library under the ISC license. It aims to calculate and obtain the position of the sun for a location defined by geographic coordinates and a specific time.
The results of the lib returns can be checked at the following site.
Developed by @fwerley 👨🏽💻
npm i sun-position
import { SunPosition } from 'sun-postion';
const coords = {
lat: -4.56454,
lng: -38.9172
}
// June 22, 2023, at 5 pm, 52 minutes and 3 seconds
const date = new Date(2023, 5, 22, 17, 52, 3);
// Initialize object
const sunPosition = new SunPosition(
// Latitude
coords.lat,
// Longitude
coords.lng,
// Date-time
date
);
// Update coordinates
// sunPosition.setLatitude(coords.lat);
// sunPosition.setLongitude(coords.lng);
// Update Date-time
// sunPosition.setDateTime(date);
// Capturing feedback from the Sun's elevation angle and azimuth
let elevation = await sunPosition.getElevation();
let azimuth = await sunPosition.getAzimuth();
Method | Return | Description |
---|---|---|
setLatitude(number)
|
void
|
Latitude coordinate in decimal degrees |
setLongitude(number)
|
void
|
Longitude coordinate in decimal degrees |
setDateTime(Date)
|
void
|
Receives a JavaScript Date object as a parameter |
Method | Return | Description |
---|---|---|
getDurationDay()
|
Array<number>
|
Array containing the total duration of the day, with three indices, in this order: hour, minute and second |
getDeclinationAngle()
|
number
|
Sun declination angle for the input date. For more details Declination Angle |
getTimeZone()
|
Promise<TimeZone>
|
Object containing timezone information{
|
getLocTime()
|
Promise<LocTime>
|
Object containing sunrise and sunset times for local standard time.{
|
getSunTime()
|
Promise<SunTime>
|
Object containing sunrise and sunset.
{
|
getElevation()
|
Promise<number>
|
Elevation of the Sun in relation to the horizon, being 0° on the horizon and 90° when the Sun is positioned above the observer. |
getAzimuth()
|
Promise<number>
|
Position of the Sun considering an imaginary line that connects the observer to the Sun, projected onto the horizontal, and with reference to geographic north. The azimuth angle is increasing with reference to the geographic north and heading east. |
- Paradigm shift to support object-oriented programming.
- Addition of the equation of time for hourly correction
- Sunrise and sunset correction
- Public version on npm