npm.io
0.1.2 • Published 1 year ago

sun-position

Licence
ISC
Version
0.1.2
Deps
1
Size
580 kB
Vulns
0
Weekly
0
Stars
1

sun-position-logo

Npm package version

TypeScript

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 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();

References
Input Functions
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
Return functions
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
{
 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

Dynamic time zone localization.

Removing dependency on third-party REST API.

Paradigm shift to support object-oriented programming.

Addition of the equation of time for hourly correction

Sunrise and sunset correction

Public version on npm

Keywords