From 9bc8abff4969e17b244786fdc4e8a967af906dc4 Mon Sep 17 00:00:00 2001 From: gimy Date: Mon, 25 Sep 2023 09:31:16 +0800 Subject: [PATCH] feat: added a set of new custom methods --- src/Base.ts | 107 ++++++++++++++++++++++++++++++++ src/types/CalculationsConfig.ts | 3 + src/types/Methods.ts | 42 ++++++++++--- 3 files changed, 145 insertions(+), 7 deletions(-) diff --git a/src/Base.ts b/src/Base.ts index 8551d4d..ba09872 100644 --- a/src/Base.ts +++ b/src/Base.ts @@ -88,6 +88,113 @@ export class BaseCalculator { return CalculationMethod.Tehran() } else if (method === Methods.TURKEY) { return CalculationMethod.Turkey() + + // Custom Methods + } else if ( + method === Methods.STANDARD || + method === Methods.JORDAN || + method === Methods.LIBYA || + method === Methods.PALESTINE || + method === Methods.SUDAN + ) { + return this._pramsFromCustomMethod({ + fajrAngle: 18, + ishaAngle: 18, + }) + } else if (method === Methods.ALGERIA) { + return this._pramsFromCustomMethod({ + fajrAngle: 18, + ishaAngle: 17, + methodAdjustments: { + maghrib: 3, + }, + }) + } else if (method === Methods.BAHRAIN) { + return this._pramsFromCustomMethod({ + fajrAngle: 18, + ishaAngle: 0, + ishaInterval: 90, + }) + } else if (method === Methods.BRUNEI || method === Methods.INDONESIA || method === Methods.MALAYSIA) { + return this._pramsFromCustomMethod({ + fajrAngle: 20, + ishaAngle: 18, + methodAdjustments: { + dhuhr: 1, + }, + }) + } else if (method === Methods.FRANCE) { + return this._pramsFromCustomMethod({ + fajrAngle: 12, + ishaAngle: 12, + }) + } else if (method === Methods.GERMANY) { + return this._pramsFromCustomMethod({ + fajrAngle: 18, + ishaAngle: 16.5, + }) + } else if (method === Methods.IRAQ) { + return this._pramsFromCustomMethod({ + fajrAngle: 19.5, + ishaAngle: 17.5, + methodAdjustments: { + dhuhr: 7, + asr: 7, + maghrib: 4, + }, + }) + } else if (method === Methods.MOROCCO) { + return this._pramsFromCustomMethod({ + fajrAngle: 19, + ishaAngle: 17, + methodAdjustments: { + dhuhr: 5, + maghrib: 2, + }, + }) + } else if (method === Methods.RUSSIA) { + return this._pramsFromCustomMethod({ + fajrAngle: 16, + ishaAngle: 15, + }) + } else if (method === Methods.OMAN) { + return this._pramsFromCustomMethod({ + fajrAngle: 18, + ishaAngle: 18, + methodAdjustments: { + dhuhr: 5, + asr: 5, + maghrib: 5, + }, + }) + } else if (method === Methods.SYRIA) { + return this._pramsFromCustomMethod({ + fajrAngle: 18.5, + ishaAngle: 17.5, + methodAdjustments: { + sunrise: -7, + dhuhr: 5, + asr: 3, + maghrib: 7, + }, + }) + } else if (method === Methods.TUNISIA) { + return this._pramsFromCustomMethod({ + fajrAngle: 18, + ishaAngle: 18, + methodAdjustments: { + dhuhr: 7, + maghrib: 2, + }, + }) + } else if (method === Methods.YEMEN) { + return this._pramsFromCustomMethod({ + fajrAngle: 18, + ishaAngle: 17, + methodAdjustments: { + dhuhr: 2, + }, + }) } else if (typeof method === 'object') { // if we receive an object for custom calculation method return this._pramsFromCustomMethod(method) diff --git a/src/types/CalculationsConfig.ts b/src/types/CalculationsConfig.ts index cfd7716..50e1c17 100644 --- a/src/types/CalculationsConfig.ts +++ b/src/types/CalculationsConfig.ts @@ -5,6 +5,9 @@ import type { Methods } from './Methods' import type { PrayerAdjustments } from './PrayerAdjustments' import type { ValueOf } from './TypesUtils' +// TODO: add a configuration to take into consideration the altitude of the location +// TODO: add a configuration to take into consideration daylight savings +// TODO: add a configuration to take into consideration ramadan timings (+30min on top of the 90min used for UmmAlQura) export interface CustomMethod { /** * Angle of the sun used to calculate Fajr diff --git a/src/types/Methods.ts b/src/types/Methods.ts index 50ccf71..249833c 100644 --- a/src/types/Methods.ts +++ b/src/types/Methods.ts @@ -1,14 +1,42 @@ export enum Methods { - UMM_AL_QURA = 'UmmAlQura', // Umm al-Qura University, Makkah - MUSLIM_WORLD_LEAGUE = 'MuslimWorldLeague', // Muslim World League + UMM_AL_QURA = 'UmmAlQura', // Umm al-Qura University, Makkah (should also use altitude) + MUSLIM_WORLD_LEAGUE = 'MuslimWorldLeague', // Muslim World League (should also use altitude) MOONSIGHTING_COMMITTEE = 'MoonsightingCommittee', // Moon sighting Committee KUWAIT = 'Kuwait', QATAR = 'Qatar', - EGYPTIAN = 'Egyptian', // Egyptian General Authority of Survey - KARACHI = 'Karachi', // University of Islamic Sciences, Karachi + EGYPTIAN = 'Egyptian', // Egyptian General Authority of Survey (should also use altitude) + KARACHI = 'Karachi', // University of Islamic Sciences, Karachi (should also use altitude) TURKEY = 'Turkey', // Dianet - DUBAI = 'Dubai', - SINGAPORE = 'Singapore', - NORTH_AMERICA = 'NorthAmerica', // ISNA + DUBAI = 'Dubai', // (should also use altitude) + SINGAPORE = 'Singapore', // Majlis Ugama Islam Singapura (MUIS) + NORTH_AMERICA = 'NorthAmerica', // ISNA (should also use altitude) TEHRAN = 'Tehran', // Institute of Geophysics, University of Tehran + // Custom Methods + // UMM_AL_QURA_RAMADAN = 'UmmAlQuraRamadan', // Umm al-Qura University, Makkah (Ramadan) - adds 30 minutes on top of the 90 minutes used for UmmAlQura (120 minutes total) + STANDARD = 'Standard', // 18 degrees + ALGERIA = 'Algeria', + BAHRAIN = 'Bahrain', + BRUNEI = 'Brunei', + FRANCE = 'France', // 12, as 15, 18 degrees is covered by ISNA and Standard respectively + GERMANY = 'Germany', // needs to be tested + INDONESIA = 'Indonesia', // Kementerian Agama Republik Indonesia (Kemenag) + IRAQ = 'Iraq', + JORDAN = 'Jordan', // (should also use altitude) + LIBYA = 'Libya', + MALAYSIA = 'Malaysia', // Jabatan Kemajuan Islam Malaysia (JAKIM) + MOROCCO = 'Morocco', // (should also use altitude) + RUSSIA = 'Russia', // needs to be tested + OMAN = 'Oman', + PALESTINE = 'Palestine', // (should also use altitude) + SUDAN = 'Sudan', + SYRIA = 'Syria', // (should also use altitude) + TUNISIA = 'Tunisia', // (should also use altitude) + YEMEN = 'Yemen', // (should also use altitude) } + +// EGYPTIAN_ALTRNATIVE = 'Other', // no method adjustments +// ISNA_ALTERNATIVE = 'Other', // no method adjustments +// MUSLIM_WORLD_LEAGUE_ALTERNATIVE = 'Other', // no method adjustments +// UMMUL_QURA_ALTERNATIVE = 'Other', // duhr adjusted 1 minute +// KARACHI_ALTERNATIVE = 'Other', // no method adjustments +// DUBAI_ALTERNATIVE = 'Other', // fajr and isha angles changed to 18 degrees and duhr adjusted 2 minute