Skip to content

Commit

Permalink
add sunset to prayers
Browse files Browse the repository at this point in the history
  • Loading branch information
jd1378 committed May 10, 2022
1 parent e2465bb commit 9d0bf0f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Adhan.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class PrayerTimes {
sunrise: Date;
dhuhr: Date;
asr: Date;
sunset: Date;
maghrib: Date;
isha: Date;

Expand Down Expand Up @@ -85,6 +86,7 @@ export interface PrayerAdjustments {
sunrise: number;
dhuhr: number;
asr: number;
sunset: number;
maghrib: number;
isha: number;
}
Expand Down Expand Up @@ -134,6 +136,7 @@ export enum Prayer {
Sunrise,
Dhuhr,
Asr,
Sunset,
Maghrib,
Isha,
None
Expand Down
1 change: 1 addition & 0 deletions src/Prayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Prayer = {
Sunrise: 'sunrise',
Dhuhr: 'dhuhr',
Asr: 'asr',
Sunset: 'sunset',
Maghrib: 'maghrib',
Isha: 'isha',
None: 'none'
Expand Down
13 changes: 12 additions & 1 deletion src/PrayerTimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ export default class PrayerTimes {
const sunriseAdjustment = (calculationParameters.adjustments.sunrise || 0) + (calculationParameters.methodAdjustments.sunrise || 0);
const dhuhrAdjustment = (calculationParameters.adjustments.dhuhr || 0) + (calculationParameters.methodAdjustments.dhuhr || 0);
const asrAdjustment = (calculationParameters.adjustments.asr || 0) + (calculationParameters.methodAdjustments.asr || 0);
const sunsetAdjustment = (calculationParameters.adjustments.sunset || 0) + (calculationParameters.methodAdjustments.sunset || 0);
const maghribAdjustment = (calculationParameters.adjustments.maghrib || 0) + (calculationParameters.methodAdjustments.maghrib || 0);
const ishaAdjustment = (calculationParameters.adjustments.isha || 0) + (calculationParameters.methodAdjustments.isha || 0);

this.fajr = roundedMinute(dateByAddingMinutes(fajrTime, fajrAdjustment), calculationParameters.rounding);
this.sunrise = roundedMinute(dateByAddingMinutes(sunriseTime, sunriseAdjustment), calculationParameters.rounding);
this.dhuhr = roundedMinute(dateByAddingMinutes(dhuhrTime, dhuhrAdjustment), calculationParameters.rounding);
this.asr = roundedMinute(dateByAddingMinutes(asrTime, asrAdjustment), calculationParameters.rounding);
this.sunset = roundedMinute(dateByAddingMinutes(sunsetTime, sunsetAdjustment), calculationParameters.rounding);
this.maghrib = roundedMinute(dateByAddingMinutes(maghribTime, maghribAdjustment), calculationParameters.rounding);
this.isha = roundedMinute(dateByAddingMinutes(ishaTime, ishaAdjustment), calculationParameters.rounding);
}
Expand All @@ -144,6 +146,9 @@ export default class PrayerTimes {
else if (prayer === Prayer.Asr) {
return this.asr;
}
else if (prayer === Prayer.Sunset) {
return this.sunset;
}
else if (prayer === Prayer.Maghrib) {
return this.maghrib;
}
Expand All @@ -165,6 +170,9 @@ export default class PrayerTimes {
else if (date >= this.maghrib) {
return Prayer.Maghrib;
}
else if (date >= this.sunset && this.sunset !== this.maghrib) {
return Prayer.Sunset;
}
else if (date >= this.asr) {
return Prayer.Asr;
}
Expand Down Expand Up @@ -192,9 +200,12 @@ export default class PrayerTimes {
else if (date >= this.maghrib) {
return Prayer.Isha;
}
else if (date >= this.asr) {
else if (date >= this.sunset) {
return Prayer.Maghrib;
}
else if (date >= this.asr && this.sunset !== this.maghrib) {
return Prayer.Sunset;
}
else if (date >= this.dhuhr) {
return Prayer.Asr;
}
Expand Down

0 comments on commit 9d0bf0f

Please sign in to comment.