salat-first
Version:
Islamic prayer times calculation with special support for Moroccan methods and Maliki madhab
35 lines (34 loc) • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SunnahTimes = void 0;
const times_1 = require("./times");
const datetime_1 = require("../core/datetime");
/**
* Class for calculating Sunnah prayer times
*/
class SunnahTimes {
/**
* Creates a new sunnah times object
* @param prayerTimes The prayer times
*/
constructor(prayerTimes) {
const date = prayerTimes.date;
const nextDay = (0, datetime_1.addDays)(date, 1);
// Calculate next day's Fajr
const nextDayPrayerTimes = new times_1.PrayerTimes(prayerTimes.coordinates, nextDay, prayerTimes.calculationParameters);
// Night duration from Maghrib to next Fajr (in milliseconds)
const nightDuration = nextDayPrayerTimes.fajr.getTime() - prayerTimes.maghrib.getTime();
// Middle of the night = Maghrib + (night duration / 2)
this.middleOfTheNight = (0, datetime_1.roundToNearestMinute)(new Date(prayerTimes.maghrib.getTime() + nightDuration / 2));
// Last third of the night = Maghrib + (night duration * 2/3)
this.lastThirdOfTheNight = (0, datetime_1.roundToNearestMinute)(new Date(prayerTimes.maghrib.getTime() + nightDuration * (2 / 3)));
}
/**
* Returns a string representation of the sunnah times
* @returns String with sunnah times
*/
toString() {
return `Middle of the Night: ${this.middleOfTheNight.toLocaleTimeString()}, Last Third of the Night: ${this.lastThirdOfTheNight.toLocaleTimeString()}`;
}
}
exports.SunnahTimes = SunnahTimes;