Skip to content

Commit

Permalink
feat(calculation methods): Add calculation methods for France with an…
Browse files Browse the repository at this point in the history
…gles 15 and 18
  • Loading branch information
Ashraf-Ali-aa committed Oct 30, 2023
1 parent 9f993c1 commit b344e25
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 65 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "@prayersconnect/configs",
"version": "3.7.0",
"version": "3.8.0",
"description": "Country specific configuration for Prayers Connect",
"main": "./lib/index.js",
"typings": "./lib/index.d.ts",
"files": [
"lib/**/*"
"lib/**/*",
"src/**/*"
],
"repository": {
"type": "git",
Expand All @@ -15,8 +16,8 @@
"license": "GPL-3.0-or-later",
"scripts": {
"build": "tsc --build tsconfig.json",
"prepare": "husky install",
"test": "jest",
"prepare": "tsc && husky install",
"test": "jest --coverage",
"test:update": "jest --updateSnapshot",
"test:watch": "jest --watch"
},
Expand Down
114 changes: 73 additions & 41 deletions src/adhan/calculation-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export const CalculationMethods: Record<
Custom: {
calculationKey: 'Custom',
label: 'Custom',
info: 'Sets a Fajr angle of 0 and an Isha angle of 0.' as const,
info: 'Fajr: 0°, Isha: 0°' as const,
get: CalculationMethod.Other,
},

Algeria: {
calculationKey: 'Algeria',
label: 'Ministry of Religious Affairs and Wakfs, Algeria',
otherLabel: 'Ministry of Religious Affairs and Wakfs',
info: 'Uses Fajr angle of 18, Isha angle of 17, + 3min maghrib',
info: 'Fajr: 18°, Magrib: +3 min, Isha: 17°',
get: () => {
const params = new CalculationParameters('Other', 18.0, 17.0);
params.methodAdjustments = {
Expand All @@ -50,44 +50,57 @@ export const CalculationMethods: Record<
calculationKey: 'Brunei',
label: 'Kementrian Hal Ehwal Ugama (Brunei Darussalam)',
otherLabel: 'Brunei Darussalam',
info: 'Uses Fajr angle of 20 and Isha angle of 18',
info: 'Fajr: 20°, Isha: 18°',
get: () => new CalculationParameters('Other', 20.0, 18.0),
},

Dubai: {
calculationKey: 'Dubai',
label: 'The Gulf Region (Dubai)',
info: 'Uses Fajr and Isha angles of 18.2 degrees.',
info: 'Fajr: 18.2°, Isha: 18.2°',
url: 'https://www.awqaf.gov.ae/en/Pages/PrayerTimes.aspx',
get: CalculationMethod.Dubai,
},

Egyptian: {
calculationKey: 'Egyptian',
label: 'Egyptian General Survey Authority',
info: 'Uses Fajr angle of 19.5 and an Isha angle of 17.5' as const,
info: 'Fajr: 19.5°, Isha: 17.5°' as const,
get: CalculationMethod.Egyptian,
region: 'Africa, Syria, Iraq, Lebanon, Malaysia, Parts of the USA' as const,
},

France: {
calculationKey: 'France',
label: 'Union Organization Islamic de France',
info: 'Uses a Fajr angle of 12 and an Isha angle of 12 by default but by setting alternativeCalculation to 15 or 18 it will updated accordingly.',
label: 'Union Organization Islamic de France - 12',
info: 'Fajr: 12.0°, Isha: 12.0°',
region: 'France region' as const,
availableMethods: ['12', '15', '18'],
get: (settings?: CalculationSettings) => {
const calculation = new CalculationParameters('Other', 12.0, 12.0);

if (settings?.alternativeCalculation === '15') {
calculation.fajrAngle = 15.0;
calculation.ishaAngle = 15.0;
}
return calculation;
},
},

if (settings?.alternativeCalculation === '18') {
calculation.fajrAngle = 18.0;
calculation.ishaAngle = 18.0;
}
France15: {
calculationKey: 'France15',
label: 'Union Organization Islamic de France - 15',
info: 'Fajr: 15.0°, Isha: 15.0°',
region: 'France region' as const,
get: (settings?: CalculationSettings) => {
const calculation = new CalculationParameters('Other', 15.0, 15.0);

return calculation;
},
},

France18: {
calculationKey: 'France18',
label: 'Union Organization Islamic de France - 18',
info: 'Fajr: 18.0°, Isha: 18.0°',
region: 'France region' as const,
get: (settings?: CalculationSettings) => {
const calculation = new CalculationParameters('Other', 18.0, 18.0);

return calculation;
},
Expand All @@ -96,23 +109,23 @@ export const CalculationMethods: Record<
Gulf: {
calculationKey: 'Gulf',
label: 'Gulf region',
info: 'Modified version of Umm al-Qura that uses a Fajr angle of 19.5.',
info: 'Fajr: 19.5°, Isha: +90 min',
get: () => new CalculationParameters('Other', 19.5, undefined, 90),
},

Jafari: {
calculationKey: 'Jafari',
label: 'Shia Ithna Ashari, Leva Institute, Qum',
otherLabel: 'Leva Institute, Qum',
info: 'Uses Fajr angle of 16, Maghrib angle of 4 and Isha angle of 14',
info: 'Fajr: 16.0°, Magrib: 4.0°, Isha: 14.0°',
get: () => new CalculationParameters('Other', 16.0, 14.0, 0, 4.0),
},

Karachi: {
calculationKey: 'Karachi',
label: 'University of Islamic Sciences, Karachi',
otherLabel: 'University of Islamic Sciences',
info: 'Uses Fajr angle of 18 and an Isha angle of 18' as const,
info: 'Fajr: 18.0°, Isha: 18.0°',
get: CalculationMethod.Karachi,
region:
'Pakistan, Bangladesh, India, Afghanistan, Parts of Europe' as const,
Expand All @@ -122,60 +135,60 @@ export const CalculationMethods: Record<
calculationKey: 'Indonesia',
label: 'Kementrian Agama Republik Indonesia (KEMENAG)',
otherLabel: 'Kementrian Agama Republik Indonesia',
info: 'Uses Fajr angle of 20.0 and Isha angle of 18',
info: 'Fajr: 20.0°, Isha: 18.0°',
get: () => new CalculationParameters('Other', 20.0, 18.0),
},

Kuwait: {
calculationKey: 'Kuwait',
label: 'Kuwait',
info: 'Uses a Fajr angle of 18 and an Isha angle of 17.5',
info: 'Fajr: 18.0°, Isha: 17.5°' as const,
get: CalculationMethod.Kuwait,
},

MoonsightingCommittee: {
calculationKey: 'MoonsightingCommittee',
label: 'Moonsighting Committee',
info: 'Uses a Fajr angle of 18 and an Isha angle of 18. Also uses seasonal adjustment values.' as const,
info: 'Fajr: 18.0°, Isha: 18.0°, Note: seasonal adjustment values.' as const,
get: CalculationMethod.MoonsightingCommittee,
region: 'UK',
},

MuslimWorldLeague: {
calculationKey: 'MuslimWorldLeague',
label: 'Muslim World League',
info: 'Uses Fajr angle of 18 and an Isha angle of 17' as const,
info: 'Fajr: 18.0°, Isha: 17.0°' as const,
get: CalculationMethod.MuslimWorldLeague,
region: 'Europe, The Far East, Parts of the USA',
},

IslamicSocietyOfNorthAmerica: {
calculationKey: 'IslamicSocietyOfNorthAmerica',
label: 'Islamic Society of North America - ISNA',
info: 'Uses a Fajr angle of 15 and an Isha angle of 15.' as const,
info: 'Fajr: 15.0°, Isha: 15.' as const,
region: 'Parts of the USA, Canada, Parts of the UK' as const,
get: CalculationMethod.NorthAmerica,
},

Qatar: {
calculationKey: 'Qatar',
label: 'Qatar',
info: 'Modified version of Umm al-Qura that uses a Fajr angle of 18.',
info: 'Fajr: 18.5°, Isha: +90 min',
url: 'https://www.qatarch.com/home',
get: CalculationMethod.Qatar,
},

Russia: {
calculationKey: 'Russia',
label: 'Spiritual Administration of Muslims of Russia',
info: 'Uses a Fajr angle of 16 and an Isha angle of 15.',
info: 'Fajr: 16.0°, Isha: 15.',
get: () => new CalculationParameters('Other', 16.0, 15.0),
},

Singapore: {
calculationKey: 'Singapore',
label: 'Singapore',
info: 'Uses a Fajr angle of 20 and an Isha angle of 18' as const,
info: 'Fajr: 20.0°, Isha: 18.0°' as const,
get: CalculationMethod.Singapore,
url: 'https://www.muis.gov.sg/',
region: 'Singapore region' as const,
Expand All @@ -184,21 +197,21 @@ export const CalculationMethods: Record<
Tehran: {
calculationKey: 'Tehran',
label: 'Shia, Institute of Geophysics, University of Tehran',
info: 'Uses Fajr angle of 17.7, Maghrib angle of 4.5 and Isha angle of 14',
info: 'Fajr: 17.7°, Magrib: 4.5°, Isha: 14.0°',
get: CalculationMethod.Tehran,
},

Tunisia: {
calculationKey: 'Tunisia',
label: 'Ministry of Religious Affairs of Tunisia',
info: 'Uses Fajr angle of 18 and Isha angle of 18',
info: 'Fajr: 18.0°, Isha: 18.0°',
get: () => new CalculationParameters('Other', 18.0, 18.0),
},

Turkey: {
calculationKey: 'Turkey',
label: 'Presidency of Religious Affairs, Turkey',
info: 'Uses a Fajr angle of 18 and an Isha angle of 17.',
info: 'Fajr: 18.0°, Isha: 17.',
url: 'https://kurul.diyanet.gov.tr/Karar-Mutalaa-Cevap/4093/45-enlemin-otesinde-namaz-vakitleri',
get: CalculationMethod.Turkey,
preAdjustments: (date: DateTime, options: PrayerTimesOptions) => {
Expand Down Expand Up @@ -255,7 +268,7 @@ export const CalculationMethods: Record<
UmmAlQura: {
calculationKey: 'UmmAlQura',
label: 'Umm al-Qura University, Makkah',
info: 'Uses a Fajr angle of 18.5 and an Isha interval of 90 minutes.\nNote: You should add a +30 minute custom adjustment of Isha during Ramadan.' as const,
info: 'Fajr: 18.5°, Isha: +90 min, Ramadan - Isha: +120 min' as const,
url: 'https://www.ummulqura.org.sa/Index.aspx' as const,
region: 'The Arabian Peninsula' as const,
get: CalculationMethod.UmmAlQura,
Expand All @@ -265,7 +278,22 @@ export const CalculationMethods: Record<
}
},
},
};
} as const;

export const HighLatitudeLabels = [
{
label: 'Middle of the Night',
key: 'middleofthenight',
},
{
label: 'Seventh of the Night',
key: 'seventhofthenight',
},
{
label: 'Twilight Angle Based',
key: 'twilightangle',
},
];

export function calculatePrayerTimes(
date: DateTime,
Expand Down Expand Up @@ -311,10 +339,18 @@ function getPrayerTimesOptionsFromSettings(
throw new Error('Required properties are missing from the settings.');
}

const calculationMethodEntry = CalculationMethods[calculationMethod];

if (!calculationMethodEntry) {
throw new Error(
`Could not find '${calculationMethodEntry}' in CalculationMethods`
);
}

const prayerTimeOptions: PrayerTimesOptions = {
calculationParameters: CalculationMethods[calculationMethod].get(settings),
calculationParameters: calculationMethodEntry.get(settings),
coordinates: new Coordinates(location.latitude, location.longitude),
calculationMethod: CalculationMethods[calculationMethod],
calculationMethod: calculationMethodEntry,
midnightMethod: midnightMethod,
midnightAdjustment: midnightAdjustment ?? 0,
};
Expand All @@ -335,7 +371,7 @@ function setRounding(
roundingMethod?: typeof Rounding[keyof typeof Rounding]
) {
prayerTimeOptions.calculationParameters.rounding =
roundingMethod || prayerTimeOptions.calculationParameters.rounding;
roundingMethod || 'nearest';
}

function setAdjustments(
Expand Down Expand Up @@ -396,12 +432,8 @@ function setShafaq(
prayerTimeOptions: PrayerTimesOptions,
shafaqCalcSetting?: typeof Shafaq[keyof typeof Shafaq]
) {
if (
prayerTimeOptions.calculationParameters.method === 'MoonsightingCommittee'
) {
prayerTimeOptions.calculationParameters.shafaq =
shafaqCalcSetting || Shafaq.General;
}
prayerTimeOptions.calculationParameters.shafaq =
shafaqCalcSetting || Shafaq.General;
}

function setPolarCircleResolution(
Expand Down
16 changes: 8 additions & 8 deletions src/adhan/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export type CalculationMethodKey =
| 'Dubai'
| 'Egyptian'
| 'France'
| 'France15'
| 'France18'
| 'Gulf'
| 'IslamicSocietyOfNorthAmerica'
| 'Jafari'
Expand Down Expand Up @@ -151,23 +153,21 @@ export type FormatOptions = {

export type AsrCalculationType = 'Standard' | 'Hanafi';

export type HighLatitudeRule =
| 'middleofthenight'
| 'seventhofthenight'
| 'twilightangle';

export type CalculationSettings = {
location: ICoords | undefined;
calculationMethod: CalculationMethodKey;
asrCalculation: AsrCalculationType;

// Used alternative calculation methods i.e france 12, 15, 18 degrees
alternativeCalculation?: string;
timezone?: string;

midnightMethod?: keyof typeof MidnightMethod;

highLatitudeRule?:
| typeof HighLatitudeRule[keyof Omit<
typeof HighLatitudeRule,
'recommended'
>]
| undefined;
highLatitudeRule?: HighLatitudeRule;
shafaq?: typeof Shafaq[keyof typeof Shafaq];
polarResolution?: string;

Expand Down
8 changes: 8 additions & 0 deletions src/countries/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ exports[`country helpers getConfigByISOName country configs Australia 1`] = `
exports[`country helpers getConfigByISOName country configs BA 1`] = `
{
"alpha2Code": "BA",
"calculationSettings": {
"asrCalculation": "Standard",
"calculationMethod": "MuslimWorldLeague",
},
"code": 70,
"features": {
"education": false,
Expand Down Expand Up @@ -216,6 +220,10 @@ exports[`country helpers getConfigByISOName country configs DZ 1`] = `
exports[`country helpers getConfigByISOName country configs EG 1`] = `
{
"alpha2Code": "EG",
"calculationSettings": {
"asrCalculation": "Standard",
"calculationMethod": "MuslimWorldLeague",
},
"code": 818,
"features": {
"education": false,
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export {
JamaatPrayer,
ICoords,
AsrCalculationType,
HighLatitudeRule,
} from './adhan/types';

export { isFriday, isRamadan, getHijriMonth, MonthFormat } from './utils/date';
export {
isFriday,
isRamadan,
isEidInDay,
getHijriMonth,
MonthFormat,
} from './utils/date';
Loading

0 comments on commit b344e25

Please sign in to comment.