Skip to content

Commit

Permalink
Fix custom method settings for calendar endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
meezaan committed Oct 3, 2023
1 parent 14d69be commit 2104abe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
15 changes: 4 additions & 11 deletions api/Models/PrayerTimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
21 changes: 11 additions & 10 deletions api/Utils/PrayerTimesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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();

Expand All @@ -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)];
}
Expand All @@ -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 = [];
Expand All @@ -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)];
}
Expand All @@ -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 = [];
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2104abe

Please sign in to comment.