PluginProbe ʕ •ᴥ•ʔ
Daily Prayer Time / 2026.05.04
Daily Prayer Time v2026.05.04
2026.05.20 2026.05.11 2026.05.09 2026.05.05 2026.05.04 2026.05.03 2026.04.28 2026.04.28.1 trunk 2019.10.16 2019.11.19 2019.2.16 2019.3.1 2019.4.1 2019.4.5 2019.5.12 2019.5.13 2019.5.14 2019.5.19 2019.5.19.1 2019.5.21 2019.5.30 2019.5.5 2019.5.6 2019.5.7 2019.5.8 2019.5.9 2019.6.10 2019.6.2 2019.6.22 2019.7.10 2019.7.25 2019.8.1 2019.8.4 2019.9.16 2020.04.25 2020.04.26 2020.05.01 2020.05.04 2020.05.08 2020.05.17 2020.07.03 2021.01.10 2021.03.28 2021.07.20 2021.07.23 2021.07.24 2021.07.28 2021.08.01 2021.08.06 2021.08.07 2021.08.10 2021.09.12 2021.09.18 2021.09.23 2021.09.24 2021.10.01 2021.10.02 2021.10.10 2021.10.11 2021.10.15 2021.10.21 2021.10.27 2021.10.29 2022.03.24 2022.04.04 2022.04.14 2022.04.15 2022.04.21 2022.04.22 2022.05.04 2022.09.19 2022.11.14 2022.11.16 2022.12.18 2022.12.20 2023.01.27 2023.02.04 2023.02.09 2023.02.21 2023.03.08 2023.03.17 2023.03.18 2023.03.20 2023.05.04 2023.08.03 2023.08.08.16 2023.08.19 2023.08.19.1 2023.10.13 2023.10.21 2023.11.26 2023.12.28 2023.12.31 2024.03.28 2024.03.29 2024.03.30 2024.04.18 2024.04.20 2024.04.22 2024.04.26 2024.08.26 2024.09.12 2024.09.14 2024.09.17 2024.12.29 2024.12.30 2025.01.02 2025.01.17 2025.02.02 2025.03.04 2025.03.06 2025.03.08 2025.03.15 2025.03.20 2025.03.26 2025.03.27 2025.04.03 2025.06.16 2025.06.29 2025.07.15 2025.08.09 2025.10.26 2026.04.26
daily-prayer-time-for-mosques / Models / StartTime / PrayTime.php
daily-prayer-time-for-mosques / Models / StartTime Last commit date
PrayTime.php 4 years ago WorldCities.php 1 year ago
PrayTime.php
625 lines
1 <?php
2
3 //--------------------- Copyright Block ----------------------
4 /*
5
6 PrayTime.php: Prayer Times Calculator (ver 1.2.2)
7 Copyright (C) 2007-2010 PrayTimes.org
8
9 Developer: Hamid Zarrabi-Zadeh
10 License: GNU LGPL v3.0
11
12 TERMS OF USE:
13 Permission is granted to use this code, with or
14 without modification, in any website or application
15 provided that credit is given to the original work
16 with a link back to PrayTimes.org.
17
18 This program is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY.
20
21 PLEASE DO NOT REMOVE THIS COPYRIGHT BLOCK.
22
23 */
24
25
26 //--------------------- Help and Manual ----------------------
27 /*
28
29 User's Manual:
30 http://praytimes.org/manual
31
32 Calculating Formulas:
33 http://praytimes.org/calculation
34
35
36
37 //------------------------ User Interface -------------------------
38
39
40 getPrayerTimes (timestamp, latitude, longitude, timeZone)
41 getDatePrayerTimes (year, month, day, latitude, longitude, timeZone)
42
43 setCalcMethod (methodID)
44 setAsrMethod (methodID)
45
46 setFajrAngle (angle)
47 setMaghribAngle (angle)
48 setIshaAngle (angle)
49 setDhuhrMinutes (minutes) // minutes after mid-day
50 setMaghribMinutes (minutes) // minutes after sunset
51 setIshaMinutes (minutes) // minutes after maghrib
52
53 setHighLatsMethod (methodID) // adjust method for higher latitudes
54
55 setTimeFormat (timeFormat)
56 floatToTime24 (time)
57 floatToTime12 (time)
58 floatToTime12NS (time)
59
60
61 //------------------------- Sample Usage --------------------------
62
63
64 $prayTime->setCalcMethod($prayTime->ISNA);
65 $times = $prayTime->getPrayerTimes(time(), 43, -80, -5);
66 print('Sunrise = '. $times[1]);
67
68
69 */
70
71
72 //--------------------- PrayTime Class -----------------------
73
74 class DPTPrayTime
75 {
76
77 //------------------------ Constants --------------------------
78
79
80 // Calculation Methods
81 var $Jafari = 0; // Ithna Ashari
82 var $Karachi = 1; // University of Islamic Sciences, Karachi
83 var $ISNA = 2; // Islamic Society of North America (ISNA)
84 var $MWL = 3; // Muslim World League (MWL)
85 var $Makkah = 4; // Umm al-Qura, Makkah
86 var $Egypt = 5; // Egyptian General Authority of Survey
87 var $Custom = 6; // Custom Setting
88 var $Tehran = 7; // Institute of Geophysics, University of Tehran
89
90 // Juristic Methods
91 var $Shafii = 0; // Shafii (standard)
92 var $Hanafi = 1; // Hanafi
93
94 // Adjusting Methods for Higher Latitudes
95 var $None = 0; // No adjustment
96 var $MidNight = 1; // middle of night
97 var $OneSeventh = 2; // 1/7th of night
98 var $AngleBased = 3; // angle/60th of night
99
100
101 // Time Formats
102 var $Time24 = 0; // 24-hour format
103 var $Time12 = 1; // 12-hour format
104 var $Time12NS = 2; // 12-hour format with no suffix
105 var $Float = 3; // floating point number
106
107 // Time Names
108 var $timeNames = array(
109 'Fajr',
110 'Sunrise',
111 'Dhuhr',
112 'Asr',
113 'Sunset',
114 'Maghrib',
115 'Isha'
116 );
117
118 var $InvalidTime = '-----'; // The string used for invalid times
119
120
121 //---------------------- Global Variables --------------------
122
123
124 var $calcMethod = 0; // caculation method
125 var $asrJuristic = 0; // Juristic method for Asr
126 var $dhuhrMinutes = 0; // minutes after mid-day for Dhuhr
127 var $adjustHighLats = 1; // adjusting method for higher latitudes
128
129 var $timeFormat = 0; // time format
130
131 var $lat; // latitude
132 var $lng; // longitude
133 var $timeZone; // time-zone
134 var $JDate; // Julian date
135
136
137 //--------------------- Technical Settings --------------------
138
139
140 var $numIterations = 1; // number of iterations needed to compute times
141
142
143 //------------------- Calc Method Parameters --------------------
144
145
146 var $methodParams = array();
147
148 /* var $methodParams[methodNum] = array(fa, ms, mv, is, iv);
149
150 fa : fajr angle
151 ms : maghrib selector (0 = angle; 1 = minutes after sunset)
152 mv : maghrib parameter value (in angle or minutes)
153 is : isha selector (0 = angle; 1 = minutes after maghrib)
154 iv : isha parameter value (in angle or minutes)
155 */
156
157
158 //----------------------- Constructors -------------------------
159
160
161 function DPTPrayTime($methodID = 0)
162 {
163
164 $this->methodParams[$this->Jafari] = array(16, 0, 4, 0, 14);
165 $this->methodParams[$this->Karachi] = array(18, 1, 0, 0, 18);
166 $this->methodParams[$this->ISNA] = array(15, 1, 0, 0, 15);
167 $this->methodParams[$this->MWL] = array(18, 1, 0, 0, 17);
168 $this->methodParams[$this->Makkah] = array(18.5, 1, 0, 1, 90);
169 $this->methodParams[$this->Egypt] = array(19.5, 1, 0, 0, 17.5);
170 $this->methodParams[$this->Tehran] = array(17.7, 0, 4.5, 0, 14);
171 $this->methodParams[$this->Custom] = array(18, 1, 0, 0, 17);
172
173 $this->setCalcMethod($methodID);
174 }
175
176 function __construct($methodID = 0)
177 {
178 $this->DPTPrayTime($methodID);
179 }
180
181
182
183 //-------------------- Interface Functions --------------------
184
185
186 // return prayer times for a given date
187 function getDatePrayerTimes($year, $month, $day, $latitude, $longitude, $timeZone)
188 {
189 $this->lat = $latitude;
190 $this->lng = $longitude;
191 $this->timeZone = $timeZone;
192 $this->JDate = $this->julianDate($year, $month, $day)- $longitude/ (15* 24);
193 return $this->computeDayTimes();
194 }
195
196 // return prayer times for a given timestamp
197 function getPrayerTimes($timestamp, $latitude, $longitude, $timeZone)
198 {
199 $date = @getdate($timestamp);
200 return $this->getDatePrayerTimes($date['year'], $date['mon'], $date['mday'],
201 $latitude, $longitude, $timeZone);
202 }
203
204 // set the calculation method
205 function setCalcMethod($methodID)
206 {
207 $this->calcMethod = $methodID;
208 }
209
210 // set the juristic method for Asr
211 function setAsrMethod($methodID)
212 {
213 if ($methodID < 0 || $methodID > 1)
214 return;
215 $this->asrJuristic = $methodID;
216 }
217
218 // set the angle for calculating Fajr
219 function setFajrAngle($angle)
220 {
221 $this->setCustomParams(array($angle, null, null, null, null));
222 }
223
224 // set the angle for calculating Maghrib
225 function setMaghribAngle($angle)
226 {
227 $this->setCustomParams(array(null, 0, $angle, null, null));
228 }
229
230 // set the angle for calculating Isha
231 function setIshaAngle($angle)
232 {
233 $this->setCustomParams(array(null, null, null, 0, $angle));
234 }
235
236 // set the minutes after mid-day for calculating Dhuhr
237 function setDhuhrMinutes($minutes)
238 {
239 $this->dhuhrMinutes = $minutes;
240 }
241
242 // set the minutes after Sunset for calculating Maghrib
243 function setMaghribMinutes($minutes)
244 {
245 $this->setCustomParams(array(null, 1, $minutes, null, null));
246 }
247
248 // set the minutes after Maghrib for calculating Isha
249 function setIshaMinutes($minutes)
250 {
251 $this->setCustomParams(array(null, null, null, 1, $minutes));
252 }
253
254 // set custom values for calculation parameters
255 function setCustomParams($params)
256 {
257 for ($i=0; $i<5; $i++)
258 {
259 if ($params[$i] == null)
260 $this->methodParams[$this->Custom][$i] = $this->methodParams[$this->calcMethod][$i];
261 else
262 $this->methodParams[$this->Custom][$i] = $params[$i];
263 }
264 $this->calcMethod = $this->Custom;
265 }
266
267 // set adjusting method for higher latitudes
268 function setHighLatsMethod($methodID)
269 {
270 $this->adjustHighLats = $methodID;
271 }
272
273 // set the time format
274 function setTimeFormat($timeFormat)
275 {
276 $this->timeFormat = $timeFormat;
277 }
278
279 // convert float hours to 24h format
280 function floatToTime24($time)
281 {
282 if (is_nan($time))
283 return $this->InvalidTime;
284 $time = $this->fixhour($time+ 0.5/ 60); // add 0.5 minutes to round
285 $hours = floor($time);
286 $minutes = floor(($time- $hours)* 60);
287 return $this->twoDigitsFormat($hours). ':'. $this->twoDigitsFormat($minutes);
288 }
289
290 // convert float hours to 12h format
291 function floatToTime12($time, $noSuffix = false)
292 {
293 if (is_nan($time))
294 return $this->InvalidTime;
295 $time = $this->fixhour($time+ 0.5/ 60); // add 0.5 minutes to round
296 $hours = floor($time);
297 $minutes = floor(($time- $hours)* 60);
298 $suffix = $hours >= 12 ? ' pm' : ' am';
299 $hours = ($hours+ 12- 1)% 12+ 1;
300 return $hours. ':'. $this->twoDigitsFormat($minutes). ($noSuffix ? '' : $suffix);
301 }
302
303 // convert float hours to 12h format with no suffix
304 function floatToTime12NS($time)
305 {
306 return $this->floatToTime12($time, true);
307 }
308
309
310
311 //---------------------- Calculation Functions -----------------------
312
313 // References:
314 // http://www.ummah.net/astronomy/saltime
315 // http://aa.usno.navy.mil/faq/docs/SunApprox.html
316
317
318 // compute declination angle of sun and equation of time
319 function sunPosition($jd)
320 {
321 $D = $jd - 2451545.0;
322 $g = $this->fixangle(357.529 + 0.98560028* $D);
323 $q = $this->fixangle(280.459 + 0.98564736* $D);
324 $L = $this->fixangle($q + 1.915* $this->dsin($g) + 0.020* $this->dsin(2*$g));
325
326 $R = 1.00014 - 0.01671* $this->dcos($g) - 0.00014* $this->dcos(2*$g);
327 $e = 23.439 - 0.00000036* $D;
328
329 $d = $this->darcsin($this->dsin($e)* $this->dsin($L));
330 $RA = $this->darctan2($this->dcos($e)* $this->dsin($L), $this->dcos($L))/ 15;
331 $RA = $this->fixhour($RA);
332 $EqT = $q/15 - $RA;
333
334 return array($d, $EqT);
335 }
336
337 // compute equation of time
338 function equationOfTime($jd)
339 {
340 $sp = $this->sunPosition($jd);
341 return $sp[1];
342 }
343
344 // compute declination angle of sun
345 function sunDeclination($jd)
346 {
347 $sp = $this->sunPosition($jd);
348 return $sp[0];
349 }
350
351 // compute mid-day (Dhuhr, Zawal) time
352 function computeMidDay($t)
353 {
354 $T = $this->equationOfTime($this->JDate+ $t);
355 $Z = $this->fixhour(12- $T);
356 return $Z;
357 }
358
359 // compute time for a given angle G
360 function computeTime($G, $t)
361 {
362 $D = $this->sunDeclination($this->JDate+ $t);
363 $Z = $this->computeMidDay($t);
364 $V = 1/15* $this->darccos((-$this->dsin($G)- $this->dsin($D)* $this->dsin($this->lat))/
365 ($this->dcos($D)* $this->dcos($this->lat)));
366 return $Z+ ($G>90 ? -$V : $V);
367 }
368
369 // compute the time of Asr
370 function computeAsr($step, $t) // Shafii: step=1, Hanafi: step=2
371 {
372 $D = $this->sunDeclination($this->JDate+ $t);
373 $G = -$this->darccot($step+ $this->dtan(abs($this->lat- $D)));
374 return $this->computeTime($G, $t);
375 }
376
377
378 //---------------------- Compute Prayer Times -----------------------
379
380
381 // compute prayer times at given julian date
382 function computeTimes($times)
383 {
384 $t = $this->dayPortion($times);
385
386 $Fajr = $this->computeTime(180- $this->methodParams[$this->calcMethod][0], $t[0]);
387 $Sunrise = $this->computeTime(180- 0.833, $t[1]);
388 $Dhuhr = $this->computeMidDay($t[2]);
389 $Asr = $this->computeAsr(1+ $this->asrJuristic, $t[3]);
390 $Sunset = $this->computeTime(0.833, $t[4]);;
391 $Maghrib = $this->computeTime($this->methodParams[$this->calcMethod][2], $t[5]);
392 $Isha = $this->computeTime($this->methodParams[$this->calcMethod][4], $t[6]);
393
394 return array($Fajr, $Sunrise, $Dhuhr, $Asr, $Sunset, $Maghrib, $Isha);
395 }
396
397
398 // compute prayer times at given julian date
399 function computeDayTimes()
400 {
401 $times = array(5, 6, 12, 13, 18, 18, 18); //default times
402
403 for ($i=1; $i<=$this->numIterations; $i++)
404 $times = $this->computeTimes($times);
405
406 $times = $this->adjustTimes($times);
407 return $this->adjustTimesFormat($times);
408 }
409
410
411 // adjust times in a prayer time array
412 function adjustTimes($times)
413 {
414 for ($i=0; $i<7; $i++)
415 $times[$i] += $this->timeZone- $this->lng/ 15;
416 $times[2] += $this->dhuhrMinutes/ 60; //Dhuhr
417 if ($this->methodParams[$this->calcMethod][1] == 1) // Maghrib
418 $times[5] = $times[4]+ $this->methodParams[$this->calcMethod][2]/ 60;
419 if ($this->methodParams[$this->calcMethod][3] == 1) // Isha
420 $times[6] = $times[5]+ $this->methodParams[$this->calcMethod][4]/ 60;
421
422 if ($this->adjustHighLats != $this->None)
423 $times = $this->adjustHighLatTimes($times);
424 return $times;
425 }
426
427
428 // convert times array to given time format
429 function adjustTimesFormat($times)
430 {
431 if ($this->timeFormat == $this->Float)
432 return $times;
433 for ($i=0; $i<7; $i++)
434 if ($this->timeFormat == $this->Time12)
435 $times[$i] = $this->floatToTime12($times[$i]);
436 else if ($this->timeFormat == $this->Time12NS)
437 $times[$i] = $this->floatToTime12($times[$i], true);
438 else
439 $times[$i] = $this->floatToTime24($times[$i]);
440 return $times;
441 }
442
443
444 // adjust Fajr, Isha and Maghrib for locations in higher latitudes
445 function adjustHighLatTimes($times)
446 {
447 $nightTime = $this->timeDiff($times[4], $times[1]); // sunset to sunrise
448
449 // Adjust Fajr
450 $FajrDiff = $this->nightPortion($this->methodParams[$this->calcMethod][0])* $nightTime;
451 if (is_nan($times[0]) || $this->timeDiff($times[0], $times[1]) > $FajrDiff)
452 $times[0] = $times[1]- $FajrDiff;
453
454 // Adjust Isha
455 $IshaAngle = ($this->methodParams[$this->calcMethod][3] == 0) ? $this->methodParams[$this->calcMethod][4] : 18;
456 $IshaDiff = $this->nightPortion($IshaAngle)* $nightTime;
457 if (is_nan($times[6]) || $this->timeDiff($times[4], $times[6]) > $IshaDiff)
458 $times[6] = $times[4]+ $IshaDiff;
459
460 // Adjust Maghrib
461 $MaghribAngle = ($this->methodParams[$this->calcMethod][1] == 0) ? $this->methodParams[$this->calcMethod][2] : 4;
462 $MaghribDiff = $this->nightPortion($MaghribAngle)* $nightTime;
463 if (is_nan($times[5]) || $this->timeDiff($times[4], $times[5]) > $MaghribDiff)
464 $times[5] = $times[4]+ $MaghribDiff;
465
466 return $times;
467 }
468
469
470 // the night portion used for adjusting times in higher latitudes
471 function nightPortion($angle)
472 {
473 if ($this->adjustHighLats == $this->AngleBased)
474 return 1/60* $angle;
475 if ($this->adjustHighLats == $this->MidNight)
476 return 1/2;
477 if ($this->adjustHighLats == $this->OneSeventh)
478 return 1/7;
479 }
480
481
482 // convert hours to day portions
483 function dayPortion($times)
484 {
485 for ($i=0; $i<7; $i++)
486 $times[$i] /= 24;
487 return $times;
488 }
489
490
491
492 //---------------------- Misc Functions -----------------------
493
494
495 // compute the difference between two times
496 function timeDiff($time1, $time2)
497 {
498 return $this->fixhour($time2- $time1);
499 }
500
501
502 // add a leading 0 if necessary
503 function twoDigitsFormat($num)
504 {
505 return ($num <10) ? '0'. $num : $num;
506 }
507
508
509
510 //---------------------- Julian Date Functions -----------------------
511
512
513 // calculate julian date from a calendar date
514 function julianDate($year, $month, $day)
515 {
516 if ($month <= 2)
517 {
518 $year -= 1;
519 $month += 12;
520 }
521 $A = floor($year/ 100);
522 $B = 2- $A+ floor($A/ 4);
523
524 $JD = floor(365.25* ($year+ 4716))+ floor(30.6001* ($month+ 1))+ $day+ $B- 1524.5;
525 return $JD;
526 }
527
528
529 // convert a calendar date to julian date (second method)
530 function calcJD($year, $month, $day)
531 {
532 $J1970 = 2440588.0;
533 $date = $year. '-'. $month. '-'. $day;
534 $ms = strtotime($date); // # of milliseconds since midnight Jan 1, 1970
535 $days = floor($ms/ (1000 * 60 * 60* 24));
536 return $J1970+ $days- 0.5;
537 }
538
539
540 //---------------------- Trigonometric Functions -----------------------
541
542 // degree sin
543 function dsin($d)
544 {
545 return sin($this->dtr($d));
546 }
547
548 // degree cos
549 function dcos($d)
550 {
551 return cos($this->dtr($d));
552 }
553
554 // degree tan
555 function dtan($d)
556 {
557 return tan($this->dtr($d));
558 }
559
560 // degree arcsin
561 function darcsin($x)
562 {
563 return $this->rtd(asin($x));
564 }
565
566 // degree arccos
567 function darccos($x)
568 {
569 return $this->rtd(acos($x));
570 }
571
572 // degree arctan
573 function darctan($x)
574 {
575 return $this->rtd(atan($x));
576 }
577
578 // degree arctan2
579 function darctan2($y, $x)
580 {
581 return $this->rtd(atan2($y, $x));
582 }
583
584 // degree arccot
585 function darccot($x)
586 {
587 return $this->rtd(atan(1/$x));
588 }
589
590 // degree to radian
591 function dtr($d)
592 {
593 return ($d * M_PI) / 180.0;
594 }
595
596 // radian to degree
597 function rtd($r)
598 {
599 return ($r * 180.0) / M_PI;
600 }
601
602 // range reduce angle in degrees.
603 function fixangle($a)
604 {
605 $a = $a - 360.0 * floor($a / 360.0);
606 $a = $a < 0 ? $a + 360.0 : $a;
607 return $a;
608 }
609
610 // range reduce hours to 0..23
611 function fixhour($a)
612 {
613 $a = $a - 24.0 * floor($a / 24.0);
614 $a = $a < 0 ? $a + 24.0 : $a;
615 return $a;
616 }
617
618 }
619
620 //---------------------- prayTime Object -----------------------
621
622 $prayTime = new DPTPrayTime();
623
624 ?>
625