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 24, 2023
1 parent 9f993c1 commit 7efc443
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 35 deletions.
7 changes: 4 additions & 3 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,7 +16,7 @@
"license": "GPL-3.0-or-later",
"scripts": {
"build": "tsc --build tsconfig.json",
"prepare": "husky install",
"prepare": "tsc && husky install",
"test": "jest",
"test:update": "jest --updateSnapshot",
"test:watch": "jest --watch"
Expand Down
78 changes: 55 additions & 23 deletions src/adhan/calculation-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,35 @@ export const CalculationMethods: Record<

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: 'Uses a Fajr angle of 12 and an Isha angle of 12.',
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: 'Uses a Fajr angle of 15 and an Isha angle of 15.',
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: 'Uses a Fajr angle of 18 and an Isha angle of 18.',
region: 'France region' as const,
get: (settings?: CalculationSettings) => {
const calculation = new CalculationParameters('Other', 18.0, 18.0);

return calculation;
},
Expand Down Expand Up @@ -129,7 +142,7 @@ export const CalculationMethods: Record<
Kuwait: {
calculationKey: 'Kuwait',
label: 'Kuwait',
info: 'Uses a Fajr angle of 18 and an Isha angle of 17.5',
info: 'Uses a Fajr angle of 18 and an Isha angle of 17.5' as const,
get: CalculationMethod.Kuwait,
},

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: 'Uses a Fajr angle of 18.5 and an Isha interval of 90 minutes, +30 minute for Isha during Ramadan.' 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,
isEidOnDay,
getHijriMonth,
MonthFormat,
} from './utils/date';
27 changes: 27 additions & 0 deletions src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,33 @@ export function isRamadan(date: DateTime): boolean {
return getHijriMonth(date, MonthFormat.NUMBER) === 9;
}

export function isEidOnDay(daysAgo: number = 0): boolean {
// Get the date x days from now
const targetDate = DateTime.local().plus({ days: daysAgo });

// Calculate the Islamic year and month for the target date
const islamicYear = targetDate.setZone('Asia/Riyadh').toFormat('o');
const islamicMonth = targetDate.setZone('Asia/Riyadh').toFormat('M');

// Check for Eid al-Fitr (1st day of Shawwal)
if (
islamicMonth === '10' &&
targetDate.setZone('Asia/Riyadh').toFormat('d') === '1'
) {
return true;
}

// Check for Eid al-Adha (10th day of Dhu al-Hijjah)
if (
islamicMonth === '12' &&
targetDate.setZone('Asia/Riyadh').toFormat('d') === '10'
) {
return true;
}

return false;
}

export function getHijriMonth(
date: DateTime,
format: MonthFormat
Expand Down

0 comments on commit 7efc443

Please sign in to comment.