sun-position
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

sun-position-logo

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 👨🏽‍💻


Installation and use

npm i sun-position
import SunPosition from 'sun-postion';
const sunPosition = SunPosition;
const coords = {
    lat: -4.56454,
    lng: -38.9172
}

//Coordinate entry
sunPosition.setLatitude(coords.lat);
sunPosition.setLongitude(coords.lng);

// June 22, 2023, at 5 pm, 52 minutes and 3 seconds
const date = new Date(2023, 5, 22, 17, 52, 3);

// Date-time object input
sunPosition.setDateTime(date);

// Capturing feedback from the Sun's elevation angle and azimuth
let elevation = await sunPosition.getElevation();
let azimuth = await sunPosition.getAzimuth();

References

Input Functions
Property 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
Return functions
Property 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
{
 countryCode: string,
 country: string,
 region: string,
 city: string,
 zoneName: string,
 gmtOffset: number, //The time offset in seconds based on UTC time.
}
getLocTime() Promise<LocTime> Object containing sunrise and sunset times for local standard time.
{
 moment: Date, //input datetime
 sunrise: Date,
 sunset: Date
}
getSunTime() Promise<SunTime> Object containing sunrise and sunset.
⚠️Solar time
No time correction to official meridian standard
{
 moment: Date,
 sunrise: Date,
 sunset: Date
}
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.

Change history

  • Addition of the equation of time for hourly correction
0.0.6 - December 24, 2023

  • Sunrise and sunset correction
0.0.5 - December 24, 2023

  • Public version on npm
0.0.4 - December 10, 2023

Package Sidebar

Install

npm i sun-position

Weekly Downloads

0

Version

0.0.6

License

ISC

Unpacked Size

52.1 kB

Total Files

8

Last publish

Collaborators

  • werley