From 2104abe9da2fc07824043a26a59738167a3110e3 Mon Sep 17 00:00:00 2001 From: Meezaan-ud-Din Abdu Dhil-Jalali Wal-Ikram Date: Tue, 3 Oct 2023 21:25:32 +0400 Subject: [PATCH] Fix custom method settings for calendar endpoints. --- api/Models/PrayerTimes.php | 15 ++++----------- api/Utils/PrayerTimesHelper.php | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/api/Models/PrayerTimes.php b/api/Models/PrayerTimes.php index f1f44b4..735d415 100644 --- a/api/Models/PrayerTimes.php +++ b/api/Models/PrayerTimes.php @@ -162,33 +162,26 @@ function (ItemInterface $item) use ($month, $year, $annual, $hijri, $expires) { $item->expiresAfter($expires); $pt = new \IslamicNetwork\PrayerTimes\PrayerTimes($this->method, $this->school); $pt->setShafaq($this->shafaq); - if ($this->method == Method::METHOD_CUSTOM) { - $methodSettings = ApiRequest::customMethod($this->methodSettings); - $customMethod = PrayerTimesHelper::createCustomMethod($methodSettings[0], - $methodSettings[1], $methodSettings[2]); - $pt->setCustomMethod($customMethod); - $pt->tune($this->tune[0], $this->tune[1], $this->tune[2], $this->tune[3], $this->tune[4], $this->tune[5], $this->tune[6], $this->tune[7], $this->tune[8]); - } if ($hijri) { if ($annual) { $times = PrayerTimesHelper::calculateHijriYearPrayerTimes($this->latitude, $this->longitude, $year, $this->timezone, $this->latitudeAdjustmentMethod, $pt, $this->midnightMode, - $this->adjustment, $this->tune, $this->iso8601); + $this->adjustment, $this->tune, $this->iso8601, $this->methodSettings); } else { $times = PrayerTimesHelper::calculateHijriMonthPrayerTimes($this->latitude, $this->longitude, $month, $year, $this->timezone, $this->latitudeAdjustmentMethod, $pt, $this->midnightMode, - $this->adjustment, $this->tune, $this->iso8601); + $this->adjustment, $this->tune, $this->iso8601, $this->methodSettings); } } else { if ($annual) { $times = PrayerTimesHelper::calculateYearPrayerTimes($this->latitude, $this->longitude, $year, $this->timezone, $this->latitudeAdjustmentMethod, $pt, $this->midnightMode, - $this->adjustment, $this->tune, $this->iso8601); + $this->adjustment, $this->tune, $this->iso8601, $this->methodSettings); } else { $times = PrayerTimesHelper::calculateMonthPrayerTimes($this->latitude, $this->longitude, $month, $year, $this->timezone, $this->latitudeAdjustmentMethod, $pt, $this->midnightMode, - $this->adjustment, $this->tune, $this->iso8601); + $this->adjustment, $this->tune, $this->iso8601, $this->methodSettings); } } diff --git a/api/Utils/PrayerTimesHelper.php b/api/Utils/PrayerTimesHelper.php index d7685dc..0bdf024 100644 --- a/api/Utils/PrayerTimesHelper.php +++ b/api/Utils/PrayerTimesHelper.php @@ -89,7 +89,7 @@ public static function nextPrayerTime($pt, $d, $latitude, $longitude, $latitudeA * @return array * @throws \Exception */ - public static function calculateMonthPrayerTimes($latitude, $longitude, $month, $year, $timezone, $latitudeAdjustmentMethod, PrayerTimes $pt, $midnightMode = 'STANDARD', $adjustment = 0, $tune = null, $timeFormat = PrayerTimes::TIME_FORMAT_24H): array + public static function calculateMonthPrayerTimes($latitude, $longitude, $month, $year, $timezone, $latitudeAdjustmentMethod, PrayerTimes $pt, $midnightMode = 'STANDARD', $adjustment = 0, $tune = null, $timeFormat = PrayerTimes::TIME_FORMAT_24H, string $methodSettings = null): array { $cs = new HijriCalendar(); @@ -102,7 +102,7 @@ public static function calculateMonthPrayerTimes($latitude, $longitude, $month, for ($i = 0; $i <= ($days_in_month - 1); $i++) { // Create date time object for this date. $calstart = new DateTime(date('Y-m-d H:i:s', $cal_start), new DateTimeZone($timezone)); - $timings = self::calculateTimings($calstart, $pt, $tune, $latitude, $longitude, $latitudeAdjustmentMethod, $midnightMode, $adjustment, $timeFormat); + $timings = self::calculateTimings($calstart, $pt, $tune, $latitude, $longitude, $latitudeAdjustmentMethod, $midnightMode, $adjustment, $timeFormat, $methodSettings); $date = ['readable' => $calstart->format('d M Y'), 'timestamp' => $calstart->format('U'), 'gregorian' => $hm[$i]['gregorian'], 'hijri' => $hm[$i]['hijri']]; $times[$i] = ['timings' => $timings, 'date' => $date, 'meta' => self::getMetaArray($pt)]; // Add 24 hours to start date @@ -125,7 +125,7 @@ public static function calculateMonthPrayerTimes($latitude, $longitude, $month, * @return array * @throws \Exception */ - public static function calculateHijriMonthPrayerTimes($latitude, $longitude, $month, $year, $timezone, $latitudeAdjustmentMethod, PrayerTimes $pt, $midnightMode = 'STANDARD', $adjustment = 0, $tune = null, $timeFormat = PrayerTimes::TIME_FORMAT_24H): array + public static function calculateHijriMonthPrayerTimes($latitude, $longitude, $month, $year, $timezone, $latitudeAdjustmentMethod, PrayerTimes $pt, $midnightMode = 'STANDARD', $adjustment = 0, $tune = null, $timeFormat = PrayerTimes::TIME_FORMAT_24H, string $methodSettings = null): array { $cs = new HijriCalendar(); @@ -136,7 +136,7 @@ public static function calculateHijriMonthPrayerTimes($latitude, $longitude, $mo foreach ($hm as $key => $i) { // Create date time object for this date. $calstart = new DateTime(date('Y-m-d H:i:s', strtotime($i['gregorian']['year'] . '-' . $i['gregorian']['month']['number'] . '-' . $i['gregorian']['day'] . ' 09:01:01')), new DateTimeZone($timezone)); - $timings = self::calculateTimings($calstart, $pt, $tune, $latitude, $longitude, $latitudeAdjustmentMethod, $midnightMode, $adjustment, $timeFormat); + $timings = self::calculateTimings($calstart, $pt, $tune, $latitude, $longitude, $latitudeAdjustmentMethod, $midnightMode, $adjustment, $timeFormat, $methodSettings); $date = ['readable' => $calstart->format('d M Y'), 'timestamp' => $calstart->format('U'), 'gregorian' => $i['gregorian'], 'hijri' => $i['hijri']]; $times[$key] = ['timings' => $timings, 'date' => $date, 'meta' => self::getMetaArray($pt)]; } @@ -156,7 +156,7 @@ public static function calculateHijriMonthPrayerTimes($latitude, $longitude, $mo * @return array * @throws \Exception */ - public static function calculateHijriYearPrayerTimes($latitude, $longitude, $year, $timezone, $latitudeAdjustmentMethod, PrayerTimes $pt, $midnightMode = 'STANDARD', $adjustment = 0, $tune = null, $timeFormat = PrayerTimes::TIME_FORMAT_24H): array + public static function calculateHijriYearPrayerTimes($latitude, $longitude, $year, $timezone, $latitudeAdjustmentMethod, PrayerTimes $pt, $midnightMode = 'STANDARD', $adjustment = 0, $tune = null, $timeFormat = PrayerTimes::TIME_FORMAT_24H, string $methodSettings = null): array { $cs = new HijriCalendar(); $times = []; @@ -169,7 +169,7 @@ public static function calculateHijriYearPrayerTimes($latitude, $longitude, $yea foreach ($hm as $key => $i) { // Create date time object for this date. $calstart = new DateTime(date('Y-m-d H:i:s', strtotime($i['gregorian']['year'] . '-' . $i['gregorian']['month']['number'] . '-' . $i['gregorian']['day'] . ' 09:01:01')), new DateTimeZone($timezone)); - $timings = self::calculateTimings($calstart, $pt, $tune, $latitude, $longitude, $latitudeAdjustmentMethod, $midnightMode, $adjustment, $timeFormat); + $timings = self::calculateTimings($calstart, $pt, $tune, $latitude, $longitude, $latitudeAdjustmentMethod, $midnightMode, $adjustment, $timeFormat, $methodSettings); $date = ['readable' => $calstart->format('d M Y'), 'timestamp' => $calstart->format('U'), 'gregorian' => $i['gregorian'], 'hijri' => $i['hijri']]; $times[$month][$key] = ['timings' => $timings, 'date' => $date, 'meta' => self::getMetaArray($pt)]; } @@ -190,7 +190,7 @@ public static function calculateHijriYearPrayerTimes($latitude, $longitude, $yea * @return array * @throws \Exception */ - public static function calculateYearPrayerTimes($latitude, $longitude, $year, $timezone, $latitudeAdjustmentMethod, PrayerTimes $pt, $midnightMode = 'STANDARD', $adjustment = 0, $tune = null, $timeFormat = PrayerTimes::TIME_FORMAT_24H): array + public static function calculateYearPrayerTimes($latitude, $longitude, $year, $timezone, $latitudeAdjustmentMethod, PrayerTimes $pt, $midnightMode = 'STANDARD', $adjustment = 0, $tune = null, $timeFormat = PrayerTimes::TIME_FORMAT_24H, string $methodSettings = null): array { $cs = new HijriCalendar(); $times = []; @@ -205,7 +205,7 @@ public static function calculateYearPrayerTimes($latitude, $longitude, $year, $t for ($i = 0; $i <= ($days_in_month - 1); $i++) { // Create date time object for this date. $calstart = new DateTime(date('Y-m-d H:i:s', $cal_start), new DateTimeZone($timezone)); - $timings = self::calculateTimings($calstart, $pt, $tune, $latitude, $longitude, $latitudeAdjustmentMethod, $midnightMode, $adjustment, $timeFormat); + $timings = self::calculateTimings($calstart, $pt, $tune, $latitude, $longitude, $latitudeAdjustmentMethod, $midnightMode, $adjustment, $timeFormat, $methodSettings); $date = ['readable' => $calstart->format('d M Y'), 'timestamp' => $calstart->format('U'), 'gregorian' => $hm[$i]['gregorian'], 'hijri' => $hm[$i]['hijri']]; $times[$month][$i] = ['timings' => $timings, 'date' => $date, 'meta' => self::getMetaArray($pt)]; // Add 24 hours to start date @@ -306,9 +306,10 @@ public static function applyMethodSpecificTuning(PrayerTimes $pt, ?array $tune, return $pt; } - private static function calculateTimings(DateTime $d, PrayerTimes $pt, ?array $tune, $latitude, $longitude, $latitudeAdjustmentMethod, $midnightMode = ' STANDARD', $adjustment = 0, $timeFormat = PrayerTimes::TIME_FORMAT_24H): array + private static function calculateTimings(DateTime $d, PrayerTimes $pt, ?array $tune, $latitude, $longitude, $latitudeAdjustmentMethod, $midnightMode = 'STANDARD', $adjustment = 0, $timeFormat = PrayerTimes::TIME_FORMAT_24H, string $methodSettings = null): array { - $pt = self::applyMethodSpecificTuning($pt, $tune, $d, $adjustment); + $methodSettings = ApiRequest::customMethod($methodSettings); + $pt = self::applyMethodSpecificTuning($pt, $tune, $d, $adjustment, $methodSettings); $timings = $pt->getTimes($d, $latitude, $longitude, null, $latitudeAdjustmentMethod, $midnightMode, $timeFormat); return Timezone::addTimezoneAbbreviation($timings, $d);