UNPKG

@yachteye/signalk-makkah-plugin

Version:
58 lines (57 loc) 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SunAndPrayTimeCalculator = void 0; const PrayTime_1 = require("./PrayTime"); class SunAndPrayTimeCalculator extends PrayTime_1.PrayTime { constructor() { super(); /** Angle to use for Sunset and Sunrise calculation. */ this.sunDegrees = 0.8333; /** Angle to use for Civic Twilight calculations. */ this.civicTwilightDegrees = 6.0; this.numIterations = 2; } /** * Return sun times for a given date. * @param year Four digit year * @param month The month component, expressed as a value between 1 and 12. * @param day The day component (value between 1 and 31). * @param latitude In decimal degrees. * @param longitude In decimal degrees. * @param timeZoneHours Time zone (hours). * @returns An object with sun times in hours. In case a time can not be calculated the properties are NULL. */ GetSunTimes(year, month, day, latitude, longitude, timeZoneHours) { // console.log('GetSunTimes()', 'y', year, 'm', month, 'day', day, 'tz', timeZoneHours); this.lat = latitude; this.lng = longitude; this.timeZone = timeZoneHours; this.JDate = this.JulianDate(year, month, day) - longitude / (15.0 * 24.0); const sunrise = this.computeSunTime(180 - this.sunDegrees, 6); const sunset = this.computeSunTime(this.sunDegrees, 18); const twilightStart = this.computeSunTime(180 - this.civicTwilightDegrees, 6); const twilightEnd = this.computeSunTime(this.civicTwilightDegrees, 18); return { sunrise: sunrise, sunset: sunset, civicTwilightStart: twilightStart, civicTwilightEnd: twilightEnd }; } computeSunTime(angle, startHour) { let timeHours = startHour; for (let iteration = 0; iteration < this.numIterations; iteration++) { timeHours = this.computeTime(angle, timeHours / 24.0); } if (isNaN(timeHours)) { return null; } else { timeHours = timeHours + this.timeZone - this.lng / 15.0; if (timeHours < 0) { timeHours += 24.0; } if (timeHours >= 24.0) { // Looks like this can happen if the time zone is not correct. timeHours -= 24.0; } return timeHours; } } } exports.SunAndPrayTimeCalculator = SunAndPrayTimeCalculator;