-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
PrayerTimes.php
832 lines (714 loc) · 24.1 KB
/
PrayerTimes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
<?php
/**
* PrayTimes.js: Prayer Times Calculator (ver 2.3)
* Copyright (C) 2007-2011 PrayTimes.org
* Copyright (C) 2015-2014 Islamic Network
* Developed in JavaScript by Hamid Zarrabi-Zadeh
* Ported to PHP by Meezaan-ud-Din Abdu Dhil-Jalali Wal-Ikram
* License: GNU LGPL v3.0
*/
namespace IslamicNetwork\PrayerTimes;
use DateInterval;
use DateTime;
use DateTimezone;
use IslamicNetwork\MoonSighting\Fajr;
use IslamicNetwork\MoonSighting\Isha;
/**
* Class PrayerTimes
* @package IslamicNetwork\PrayerTimes
*/
class PrayerTimes
{
/**
* Constants for all items the times are computed for
*/
const IMSAK = 'Imsak';
const FAJR = 'Fajr';
const SUNRISE = 'Sunrise';
const ZHUHR = 'Dhuhr';
const ASR = 'Asr';
const SUNSET = 'Sunset';
const MAGHRIB = 'Maghrib';
const ISHA = 'Isha';
const MIDNIGHT = 'Midnight';
const FIRST_THIRD = 'Firstthird';
const LAST_THIRD = 'Lastthird';
/**
* Schools that determine the Asr shadow for the purpose of this class
*/
const SCHOOL_STANDARD = 'STANDARD'; //0
const SCHOOL_HANAFI = 'HANAFI'; // 1
/**
* Midnight Mode - how the midnight time is determined
*/
const MIDNIGHT_MODE_STANDARD = 'STANDARD'; // Mid Sunset to Sunrise
const MIDNIGHT_MODE_JAFARI = 'JAFARI'; // Mid Sunset to Fajr
/**
* Higher Latitude Adjustment Methods
*/
const LATITUDE_ADJUSTMENT_METHOD_MOTN = 'MIDDLE_OF_THE_NIGHT'; // 1
const LATITUDE_ADJUSTMENT_METHOD_ANGLE = 'ANGLE_BASED'; // 3, angle/60th of night
const LATITUDE_ADJUSTMENT_METHOD_ONESEVENTH = 'ONE_SEVENTH'; // 2
const LATITUDE_ADJUSTMENT_METHOD_NONE = 'NONE'; // 0
/**
* Formats in which data can be output
*/
const TIME_FORMAT_24H = '24h'; // 24-hour format
const TIME_FORMAT_12H = '12h'; // 12-hour format
const TIME_FORMAT_12hNS = '12hNS'; // 12-hour format with no suffix
const TIME_FORMAT_FLOAT = 'Float'; // floating point number
const TIME_FORMAT_ISO8601 = 'iso8601';
/**
* If we're unable to calculate a time, we'll return this
*/
const INVALID_TIME = '-----';
/**
* @Array
*/
public $methods;
/**
* @Array
*/
public $methodCodes;
/**
* @object DateTime
*/
private DateTime $date;
/**
* @String
*/
private string $method;
/**
* @Sstring
*/
private string $school = self::SCHOOL_STANDARD;
/**
* @String
*/
private string $midnightMode;
/**
* @String
*/
private string $latitudeAdjustmentMethod;
/**
* @String
*/
private string $timeFormat;
/**
* @String
*/
private $latitude;
/**
* @String
*/
private $longitude;
/**
* @String
*/
private $elevation;
/**
* @String
*/
private $asrShadowFactor = null;
/**
* @String
*/
private $settings;
/**
* @String
*/
private $shafaq = Isha::SHAFAQ_GENERAL; // Only valid for METHOD_MOONSIGHTING
/**
* @String
*/
private $offset = [];
/**
* @param string $method
* @param string $school
* @param null $asrShadowFactor If specified, this will override the school setting
* @param array|null $offset
*/
public function __construct($method = Method::METHOD_MWL, $school = self::SCHOOL_STANDARD, $asrShadowFactor = null)
{
$this->loadMethods();
$this->setMethod($method);
$this->setSchool($school);
if ($asrShadowFactor !== null) {
$this->asrShadowFactor = $asrShadowFactor;
}
$this->loadSettings();
}
public function setShafaq(string $shafaq)
{
$this->shafaq = $shafaq;
}
/**
* @param Method $method [description]
*/
public function setCustomMethod(Method $method)
{
$this->setMethod(Method::METHOD_CUSTOM);
$this->methods[$this->method] = get_object_vars($method);
$this->loadSettings();
}
private function loadSettings(): void
{
$this->settings = new \stdClass();
$this->settings->{self::IMSAK} = isset($this->methods[$this->method]['params'][self::IMSAK]) ? $this->methods[$this->method]['params'][self::IMSAK] : '10 min';
$this->settings->{self::FAJR} = isset($this->methods[$this->method]['params'][self::FAJR]) ? $this->methods[$this->method]['params'][self::FAJR] : 0;
$this->settings->{self::ZHUHR} = isset($this->methods[$this->method]['params'][self::ZHUHR]) ? $this->methods[$this->method]['params'][self::ZHUHR] : '0 min';
$this->settings->{self::ISHA} = isset($this->methods[$this->method]['params'][self::ISHA]) ? $this->methods[$this->method]['params'][self::ISHA] : 0;
$this->settings->{self::MAGHRIB} = isset($this->methods[$this->method]['params'][self::MAGHRIB]) ? $this->methods[$this->method]['params'][self::MAGHRIB] : '0 min';
// Pick up methods midnightMode
if (isset($this->methods[$this->method]['params'][self::MIDNIGHT]) && $this->methods[$this->method]['params'][self::MIDNIGHT] == self::MIDNIGHT_MODE_JAFARI) {
$this->setMidnightMode(self::MIDNIGHT_MODE_JAFARI);
} else {
$this->setMidnightMode(self::MIDNIGHT_MODE_STANDARD);
}
}
/**
* @param $latitude
* @param $longitude
* @param $timezone
* @param null $elevation
* @param string $latitudeAdjustmentMethod
* @param null $midnightMode
* @param string $format
* @return mixed
* @throws \Exception
*/
public function getTimesForToday($latitude, $longitude, $timezone, $elevation = null, $latitudeAdjustmentMethod = self::LATITUDE_ADJUSTMENT_METHOD_ANGLE, $midnightMode = null, $format = self::TIME_FORMAT_24H)
{
$date = new DateTime('', new DateTimezone($timezone));
return $this->getTimes($date, $latitude, $longitude, $elevation, $latitudeAdjustmentMethod, $midnightMode, $format);
}
/**
* @param DateTime $date
* @param $latitude
* @param $longitude
* @param $elevation
* @param string $latitudeAdjustmentMethod
* @param string $midnightMode
* @param string $format
* @return mixed
*/
public function getTimes(DateTime $date, $latitude, $longitude, $elevation = null, $latitudeAdjustmentMethod = self::LATITUDE_ADJUSTMENT_METHOD_ANGLE, $midnightMode = null, $format = self::TIME_FORMAT_24H)
{
$this->latitude = 1 * $latitude;
$this->longitude = 1 * $longitude;
$this->elevation = $elevation === null ? 0 : 1 * $elevation;
$this->setTimeFormat($format);
$this->setLatitudeAdjustmentMethod($latitudeAdjustmentMethod);
if ($midnightMode !== null) {
$this->setMidnightMode($midnightMode);
}
$this->date = $date;
return $this->computeTimes();
}
/**
* @return Array
*/
private function computeTimes()
{
// default times
$times = [
self::IMSAK => 5,
self::FAJR => 5,
self::SUNRISE => 6,
self::ZHUHR => 12,
self::ASR => 13,
self::SUNSET => 18,
self::MAGHRIB => 18,
self::ISHA => 18
];
$times = $this->computePrayerTimes($times);
$times = $this->adjustTimes($times);
// add night times
$diff = ($this->midnightMode == self::MIDNIGHT_MODE_JAFARI) ? $this->timeDiff($times[self::SUNSET], $times[self::FAJR]) : $this->timeDiff($times[self::SUNSET], $times[self::SUNRISE]);
$times[self::MIDNIGHT] = $times[self::SUNSET] + $diff / 2;
$times[self::FIRST_THIRD] = $times[self::SUNSET] + $diff / 3;
$times[self::LAST_THIRD] = $times[self::SUNSET] + 2 * ($diff / 3);
// If our method is Moonsighting, reset the Fajr and Isha times
if ($this->method == Method::METHOD_MOONSIGHTING) {
$times =$this->moonsightingRecalculation($times);
}
$times = $this->tuneTimes($times);
return $this->modifyFormats($times);
}
public function moonsightingRecalculation(array $times): array
{
// Reset Fajr
$fajrMS = new Fajr($this->date, $this->latitude);
$times[self::FAJR] = $times[self::SUNRISE] - ($fajrMS->getMinutesBeforeSunrise() / 60);
// Fajr has changed, also reset Imask
if ($this->isMin($this->settings->{self::IMSAK})) {
$times[self::IMSAK] = $times[self::FAJR] - $this->evaluate($this->settings->{self::IMSAK})/ 60;
}
// Reset Isha
$ishaMS = new Isha($this->date, $this->latitude, $this->shafaq);
$times[self::ISHA] = $times[self::SUNSET] + ($ishaMS->getMinutesAfterSunset()/60);
return $times;
}
/**
* @param $times
* @return Array
*/
private function modifyFormats($times)
{
foreach ($times as $i => $t) {
$times[$i] = $this->getFormattedTime($t, $this->timeFormat, $i);
}
return $times;
}
/**
* @param $time
* @param $format
* @return string
*/
private function getFormattedTime($time, $format, $prayer)
{
if (is_nan($time)) {
return self::INVALID_TIME;
}
if ($format == self::TIME_FORMAT_FLOAT) {
return $time;
}
$suffixes = ['am', 'pm'];
$time = $time + 0.5/ 60; // add 0.5 minutes for rounding (when we later truncate)
$fixTime = DMath::fixHour($time); // wrap to 00h-23h
$hours = floor($fixTime);
$minutes = floor(($fixTime - $hours)* 60);
$suffix = ($this->timeFormat == self::TIME_FORMAT_12H) ? $suffixes[$hours < 12 ? 0 : 1] : '';
$hour = ($format == self::TIME_FORMAT_24H) ? $this->twoDigitsFormat($hours) : (($hours+ 12 -1)% 12+ 1);
$twoDigitMinutes = $this->twoDigitsFormat($minutes);
if ($format == self::TIME_FORMAT_ISO8601) {
// Create temporary date object
$date = clone $this->date;
$date->setTime(0, 0);
if ($time > 0) {
$date->add(new DateInterval('PT' . floor($time * 60) . 'M'));
} else {
$date->sub(new DateInterval('PT' . ceil(-$time * 60) . 'M'));
}
return $date->format(DateTime::ATOM);
}
return $hour . ':' . $twoDigitMinutes . ($suffix ? ' ' . $suffix : '');
}
/**
* @param $num
* @return string
*/
private function twoDigitsFormat($num)
{
return ($num <10) ? '0'. $num : $num;
}
/**
* @param $times
* @return mixed
*/
private function tuneTimes($times)
{
if (!empty($this->offset)) {
foreach ($times as $i => $t) {
if (isset($this->offset[$i])) {
$times[$i] += $this->offset[$i] / 60;
}
}
}
return $times;
}
/**
* @param $str
* @return mixed
*/
private function evaluate($str)
{
//$str = preg_replace('/\D/', '', $str);
return floatval($str);
}
/**
* @param $times
* @return mixed
*/
private function adjustTimes($times)
{
$dateTimeZone = $this->date->getTimezone();
foreach ($times as $i => $t) {
$times[$i] += ($dateTimeZone->getOffset($this->date)/3600) - $this->longitude / 15;
}
if ($this->latitudeAdjustmentMethod != self::LATITUDE_ADJUSTMENT_METHOD_NONE) {
$times = $this->adjustHighLatitudes($times);
}
if ($this->isMin($this->settings->{self::IMSAK})) {
$times[self::IMSAK] = $times[self::FAJR] - $this->evaluate($this->settings->{self::IMSAK})/ 60;
}
if ($this->isMin($this->settings->{self::MAGHRIB})) {
$times[self::MAGHRIB] = $times[self::SUNSET] + $this->evaluate($this->settings->{self::MAGHRIB})/ 60;
}
if ($this->isMin($this->settings->{self::ISHA})) {
$times[self::ISHA] = $times[self::MAGHRIB] + $this->evaluate($this->settings->{self::ISHA})/ 60;
}
$times[self::ZHUHR] += $this->evaluate($this->settings->{self::ZHUHR})/ 60;
return $times;
}
/**
* @param $times
* @return mixed
*/
private function adjustHighLatitudes($times)
{
$nightTime = $this->timeDiff($times[self::SUNSET], $times[self::SUNRISE]);
$times[self::IMSAK] = $this->adjustHLTime($times[self::IMSAK], $times[self::SUNRISE], $this->evaluate($this->settings->{self::IMSAK}), $nightTime, 'ccw');
$times[self::FAJR] = $this->adjustHLTime($times[self::FAJR], $times[self::SUNRISE], $this->evaluate($this->settings->{self::FAJR}), $nightTime, 'ccw');
$times[self::ISHA] = $this->adjustHLTime($times[self::ISHA], $times[self::SUNSET], $this->evaluate($this->settings->{self::ISHA}), $nightTime);
$times[self::MAGHRIB] = $this->adjustHLTime($times[self::MAGHRIB], $times[self::SUNSET], $this->evaluate($this->settings->{self::MAGHRIB}), $nightTime);
return $times;
}
/**
* @param $str
* @return bool
*/
private function isMin($str)
{
if (strpos($str, 'min') !== false) {
return true;
}
return false;
}
/**
* @param $time
* @param $base
* @param $angle
* @param $night
* @param null $direction
* @return mixed
*/
private function adjustHLTime($time, $base, $angle, $night, $direction = null)
{
$portion = $this->nightPortion($angle, $night);
$timeDiff = ($direction == 'ccw') ? $this->timeDiff($time, $base): $this->timeDiff($base, $time);
if (is_nan($time) || $timeDiff > $portion) {
$time = $base + ($direction == 'ccw' ? (- $portion) : $portion);
}
return $time;
}
/**
* @param $angle
* @param $night
* @return float
*/
private function nightPortion($angle, $night)
{
$method = $this->latitudeAdjustmentMethod;
$portion = 1/2; // MidNight
if ($method == self::LATITUDE_ADJUSTMENT_METHOD_ANGLE) {
$portion = 1/60 * $angle;
}
if ($method == self::LATITUDE_ADJUSTMENT_METHOD_ONESEVENTH) {
$portion = 1/7;
}
return $portion * $night;
}
/**
* @param $t1
* @param $t2
* @return mixed
*/
private function timeDiff($t1, $t2)
{
return DMath::fixHour($t2 - $t1);
}
/**
* @param $times
* @return array
*/
private function computePrayerTimes($times)
{
$times = $this->dayPortion($times);
$imsak = $this->sunAngleTime($this->evaluate($this->settings->{self::IMSAK}), $times[self::IMSAK], 'ccw');
$sunrise = $this->sunAngleTime($this->riseSetAngle(), $times[self::SUNRISE], 'ccw');
$fajr = $this->sunAngleTime($this->evaluate($this->settings->{self::FAJR}), $times[self::FAJR], 'ccw');
$dhuhr = $this->midDay($times[self::ZHUHR]);
$asr = $this->asrTime($this->asrFactor(), $times[self::ASR]);
$sunset = $this->sunAngleTime($this->riseSetAngle(), $times[self::SUNSET]);
$maghrib = $this->sunAngleTime($this->evaluate($this->settings->{self::MAGHRIB}), $times[self::MAGHRIB]);
$isha = $this->sunAngleTime($this->evaluate($this->settings->{self::ISHA}), $times[self::ISHA]);
return [
self::FAJR => $fajr,
self::SUNRISE => $sunrise,
self::ZHUHR => $dhuhr,
self::ASR => $asr,
self::SUNSET => $sunset,
self::MAGHRIB => $maghrib,
self::ISHA => $isha,
self::IMSAK => $imsak,
];
}
/**
* An Addendum to the PHP method to return a float with the fraction of the day instead of an int.
* See https://www.php.net/manual/en/function.gregoriantojd.php.
* @param int $month
* @param int $day
* @param int $year
* @return float
*/
private function gregorianToJulianDate(): float
{
$julianDate = gregoriantojd($this->date->format('n'), $this->date->format('d'), $this->date->format('Y'));
//correct for half-day offset
$dayfrac = $this->date->format('G') / 24 - .5;
if ($dayfrac < 0) $dayfrac += 1;
//now set the fraction of a day
$frac = $dayfrac + ($this->date->format('i') + $this->date->format('s') / 60) / 60 / 24;
return ($julianDate + $frac);
}
/**
* @param $factor
* @param $time
* @return mixed
*/
private function asrTime($factor, $time)
{
$julianDate = $this->gregorianToJulianDate();
$decl = ($this->sunPosition($julianDate + $time))->declination;
$angle = -DMath::arccot($factor+ DMath::tan(abs($this->latitude- $decl)));
return $this->sunAngleTime($angle, $time);
}
/**
* @return int|null
*/
private function sunAngleTime($angle, $time, $direction = null)
{
$julianDate = $this->julianDate($this->date->format('Y'), $this->date->format('n'), $this->date->format('d')) - $this->longitude / (15* 24);
$decl = $this->sunPosition($julianDate + $time)->declination;
$noon = $this->midDay($time);
$p1 = -DMath::sin($angle) - DMath::sin($decl) * DMath::sin($this->latitude);
$p2 = DMath::cos($decl) * DMath::cos($this->latitude);
$cosRange = ($p1/$p2);
if ($cosRange > 1) {
$cosRange = 1;
}
if ($cosRange < -1) {
$cosRange = -1;
}
$t = 1/15 * DMath::arccos($cosRange);
return $noon + ($direction == 'ccw' ? -$t : $t);
}
private function asrFactor()
{
if ($this->asrShadowFactor !== null) {
return $this->asrShadowFactor;
}
if ($this->school == self::SCHOOL_STANDARD) {
return 1;
} elseif ($this->school == self::SCHOOL_HANAFI) {
return 2;
} else {
return 0;
}
}
/**
* @return float
*/
private function riseSetAngle()
{
//var earthRad = 6371009; // in meters
//var angle = DMath.arccos(earthRad/(earthRad+ elv));
$angle = 0.0347* sqrt($this->elevation); // an approximation
return 0.833+ $angle;
}
/**
* @param $julianDate
* @return stdClass
*/
private function sunPosition($julianDate)
{
// compute declination angle of sun and equation of time
// Ref: http://aa.usno.navy.mil/faq/docs/SunApprox.php
$D = $julianDate - 2451545.0;
$g = DMath::fixAngle(357.529 + 0.98560028* $D);
$q = DMath::fixAngle(280.459 + 0.98564736* $D);
$L = DMath::fixAngle($q + 1.915 * DMath::sin($g) + 0.020 * DMath::sin(2*$g));
$R = 1.00014 - 0.01671* DMath::cos($g) - 0.00014* DMath::cos(2*$g);
$e = 23.439 - 0.00000036* $D;
$RA = DMath::arctan2(DMath::cos($e)* DMath::sin($L), DMath::cos($L))/ 15;
$eqt = $q/15 - DMath::fixHour($RA);
$decl = DMath::arcsin(DMath::sin($e)* DMath::sin($L));
$res = new \stdClass();
$res->declination = $decl;
$res->equation = $eqt;
return $res;
}
/**
* @param $year
* @param $month
* @param $day
* @return float
*/
private function julianDate($year, $month, $day)
{
if ($month <= 2) {
$year -= 1;
$month += 12;
}
$A = floor($year/ 100);
$B = 2- $A+ floor($A/ 4);
$JD = floor(365.25* ($year+ 4716))+ floor(30.6001* ($month+ 1))+ $day+ $B- 1524.5;
return $JD;
}
/**
* @param $time
* @return mixed
*/
private function midDay($time)
{
$julianDate = $this->julianDate($this->date->format('Y'), $this->date->format('n'), $this->date->format('d')) - $this->longitude/ (15* 24);
$eqt = $this->sunPosition($julianDate + $time)->equation;
$noon = DMath::fixHour(12 - $eqt);
return $noon;
}
/**
* @param $times
* @return mixed
*/
private function dayPortion($times)
{
// convert hours to day portions
foreach ($times as $i => $time) {
$times[$i] = $time / 24;
}
return $times;
}
/**
* @param string $method
*/
public function setMethod($method = Method::METHOD_MWL)
{
if (in_array($method, $this->methodCodes)) {
$this->method = $method;
} else {
$this->method = Method::METHOD_MWL; // Default to MWL
}
}
/**
* @param string $method
*/
public function setAsrJuristicMethod($method = self::SCHOOL_STANDARD)
{
if (in_array($method, [self::SCHOOL_HANAFI, self::SCHOOL_STANDARD])) {
$this->school = $method;
} else {
$this->school = self::SCHOOL_STANDARD;
}
}
/**
* @param string $school
*/
public function setSchool($school = self::SCHOOL_STANDARD)
{
$this->setAsrJuristicMethod($school);
}
/**
* @param string $mode
*/
public function setMidnightMode($mode = self::MIDNIGHT_MODE_STANDARD)
{
if (in_array($mode, [self::MIDNIGHT_MODE_JAFARI, self::MIDNIGHT_MODE_STANDARD])) {
$this->midnightMode = $mode;
} else {
$this->midnightMode = self::MIDNIGHT_MODE_STANDARD;
}
}
/**
* @param string $method
*/
public function setLatitudeAdjustmentMethod($method = self::LATITUDE_ADJUSTMENT_METHOD_ANGLE)
{
if (in_array($method, [self::LATITUDE_ADJUSTMENT_METHOD_MOTN, self::LATITUDE_ADJUSTMENT_METHOD_ANGLE, self::LATITUDE_ADJUSTMENT_METHOD_ONESEVENTH, self::LATITUDE_ADJUSTMENT_METHOD_NONE ])) {
$this->latitudeAdjustmentMethod = $method;
} else {
$this->latitudeAdjustmentMethod = self::LATITUDE_ADJUSTMENT_METHOD_ANGLE;
}
}
/**
* @param string $format
*/
public function setTimeFormat($format = self::TIME_FORMAT_24H)
{
if (in_array($format, [self::TIME_FORMAT_ISO8601, self::TIME_FORMAT_24H, self::TIME_FORMAT_FLOAT, self::TIME_FORMAT_12hNS, self::TIME_FORMAT_12H])) {
$this->timeFormat = $format;
} else {
$this->timeFormat = self::TIME_FORMAT_24H;
}
}
/**
* @param int $imsak
* @param int $fajr
* @param int $sunrise
* @param int $dhuhr
* @param int $asr
* @param int $maghrib
* @param int $sunset
* @param int $isha
* @param int $midnight
*/
public function tune($imsak = 0, $fajr = 0, $sunrise = 0, $dhuhr = 0, $asr = 0, $maghrib = 0, $sunset = 0, $isha = 0, $midnight = 0)
{
$this->offset = [
self::IMSAK => $imsak,
self::FAJR => $fajr,
self::SUNRISE => $sunrise,
self::ZHUHR => $dhuhr,
self::ASR => $asr,
self::MAGHRIB => $maghrib,
self::SUNSET => $sunset,
self::ISHA => $isha,
self::MIDNIGHT => $midnight
];
}
/**
* Loads all the default settings for calculation methods
*/
public function loadMethods()
{
$this->methods = Method::getMethods();
$this->methodCodes = Method::getMethodCodes();
}
/**
* [getMethods description]
* @return [type] [description]
*/
public function getMethods()
{
return $this->methods;
}
/**
* [getMethod description]
* @return [type] [description]
*/
public function getMethod()
{
return $this->method;
}
public function getMeta(): array
{
$result = [
'latitude' => $this->latitude,
'longitude' => $this->longitude,
'timezone' => ($this->date->getTimezone())->getName(),
'method' => $this->methods[$this->method],
'latitudeAdjustmentMethod' => $this->latitudeAdjustmentMethod,
'midnightMode' => $this->midnightMode,
'school' => $this->school,
'offset' => $this->offset,
];
if (isset($result['method']['offset'])) {
unset($result['method']['offset']);
}
if ($this->method == Method::METHOD_MOONSIGHTING) {
$result['latitudeAdjustmentMethod'] = self::LATITUDE_ADJUSTMENT_METHOD_NONE;
$result['method']['params']['shafaq'] = $this->shafaq;
}
return $result;
}
}