sunmoontimes
v3.0.0
Published
A JavaScript library to calculate sunrise, sunset, moonrise, moonset and twilight times based on latitude, longitude, date, and timezone.
Downloads
19
Maintainers
Readme
SunMoonTimes
SunMoonTimes is a JavaScript library to calculate sunrise, sunset, moonrise, moonset and twilight times based on latitude, longitude, date, and timezone.
Installation
You can install the package using npm:
npm install sunmoontimes
Example Usage
// Import the SunMoonTimes library
const SunMoonTimes = require('sunmoontimes');
// Set desired values
const latitude = 30.0444; // Set latitude
const longitude = 31.2357; // Set longitude
const timezone = 3; // Set timezone offset
const date = new Date(); // Set the date
const timeformat = "12h"; // Set timeFormat
// Create an instance of SunMoonTimes
const sunMoonTimes = new SunMoonTimes(latitude, longitude, timezone, date, timeformat);
// Accessing the times after execution
console.log("Sunrise:", sunMoonTimes.sunrise);
console.log("Sunset:", sunMoonTimes.sunset);
console.log("Civil Twilight Begin:", sunMoonTimes.civilTwilightBegin);
console.log("Civil Twilight End:", sunMoonTimes.civilTwilightEnd);
console.log("Nautical Twilight Begin:", sunMoonTimes.nauticalTwilightBegin);
console.log("Nautical Twilight End:", sunMoonTimes.nauticalTwilightEnd);
console.log("Astronomical Twilight Begin:", sunMoonTimes.astronomicalTwilightBegin);
console.log("Astronomical Twilight End:", sunMoonTimes.astronomicalTwilightEnd);
console.log("Moonrise:", sunMoonTimes.moonrise);
console.log("Moonset:", sunMoonTimes.moonset);
Time Formats
Here are the available time formats: | Format | Description | Example | |--------|--------------------------------|----------| | 24h | 24-hour time format | 16:45 | | 12h | 12-hour time format | 4:45 pm | | 12hNS | 12-hour format with no suffix | 4:45 |
Credits
The original functions were adapted from http://hinch.me.uk/riset.html.
License
This project is licensed under the ISC License.