UNPKG

salat-first

Version:

Islamic prayer times calculation with special support for Moroccan methods and Maliki madhab

118 lines (117 loc) 4.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PrayerCalculator = exports.CalculationParameters = void 0; const coordinates_1 = require("../core/coordinates"); const madhab_1 = require("../madhab"); const methods_1 = require("../methods"); const times_1 = require("./times"); const formatting_1 = require("../utils/formatting"); const shadow_1 = require("../core/shadow"); /** * Calculation parameters for prayer times */ class CalculationParameters { /** * Creates a new calculation parameters object * @param method The calculation method * @param fajrAngle Angle of the sun below the horizon for Fajr * @param ishaAngle Angle of the sun below the horizon for Isha * @param ishaInterval Minutes after Maghrib for Isha (if > 0, ishaAngle is not used) * @param maghribAngle Angle of the sun below the horizon for Maghrib */ constructor(method, fajrAngle = 0, ishaAngle = 0, ishaInterval = 0, maghribAngle = 0) { this.method = method; this.fajrAngle = fajrAngle; this.ishaAngle = ishaAngle; this.ishaInterval = ishaInterval; this.maghribAngle = maghribAngle; /** * Madhab for Asr calculation */ this.madhab = madhab_1.Madhab.Shafi; /** * Manual adjustments (in minutes) to be added to each prayer time */ this.adjustments = { fajr: 0, sunrise: 0, dhuhr: 0, asr: 0, maghrib: 0, isha: 0, }; /** * Adjustments set by a calculation method (in minutes) */ this.methodAdjustments = { fajr: 0, sunrise: 0, dhuhr: 0, asr: 0, maghrib: 0, isha: 0, }; /** * How seconds are rounded when calculating prayer times */ this.rounding = formatting_1.Rounding.Nearest; } /** * Gets the shadow length multiplier for the current madhab * @returns The shadow length multiplier */ getShadowLength() { return (0, shadow_1.getShadowLengthMultiplier)((0, madhab_1.getShadowMethod)(this.madhab)); } } exports.CalculationParameters = CalculationParameters; /** * Main calculator for prayer times */ class PrayerCalculator { /** * Calculates prayer times for a specific location and date * @param latitude Latitude of the location * @param longitude Longitude of the location * @param date Date for prayer calculation (defaults to today) * @param method Calculation method (defaults to MoroccanHabous) * @param madhab Madhab for Asr calculation (defaults to method's default) * @returns Prayer times object */ static getPrayerTimes(latitude, longitude, date = new Date(), method = methods_1.CalculationMethod.MoroccanHabous, madhab) { const coordinates = new coordinates_1.Coordinates(latitude, longitude); const params = (0, methods_1.getParameters)(method); // Override madhab if specified if (madhab) { params.madhab = madhab; } return new times_1.PrayerTimes(coordinates, date, params); } /** * Gets the current prayer for a specific location and time * @param latitude Latitude of the location * @param longitude Longitude of the location * @param date Date and time to check (defaults to now) * @param method Calculation method (defaults to MoroccanHabous) * @returns The current prayer name */ static getCurrentPrayer(latitude, longitude, date = new Date(), method = methods_1.CalculationMethod.MoroccanHabous) { const prayerDate = new Date(date.getFullYear(), date.getMonth(), date.getDate()); const prayers = PrayerCalculator.getPrayerTimes(latitude, longitude, prayerDate, method); return prayers.getCurrentPrayer(date); } /** * Gets the next prayer for a specific location and time * @param latitude Latitude of the location * @param longitude Longitude of the location * @param date Date and time to check (defaults to now) * @param method Calculation method (defaults to MoroccanHabous) * @returns The next prayer name */ static getNextPrayer(latitude, longitude, date = new Date(), method = methods_1.CalculationMethod.MoroccanHabous) { const prayerDate = new Date(date.getFullYear(), date.getMonth(), date.getDate()); const prayers = PrayerCalculator.getPrayerTimes(latitude, longitude, prayerDate, method); return prayers.getNextPrayer(date); } } exports.PrayerCalculator = PrayerCalculator;