-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalendar.php
56 lines (52 loc) · 2.02 KB
/
calendar.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
<?php
//------------------------------------------------------------------------------------------
function gregorian_to_hijri($y, $m, $d) {
//------------------------------------------------------------------------------------------
return jd_to_hijri(cal_to_jd(CAL_GREGORIAN, $m, $d, $y));
}
//------------------------------------------------------------------------------------------
function hijri_to_gregorian($y, $m, $d) {
//------------------------------------------------------------------------------------------
/* Return value is in this format:
Array
(
[date] => 11/4/1969
[month] => 11
[day] => 4
[year] => 1969
[dow] => 2
[abbrevdayname] => Tue
[dayname] => Tuesday
[abbrevmonth] => Nov
[monthname] => November
)
*/
return cal_from_jd(hijri_to_jd($m, $d, $y), CAL_GREGORIAN);
}
//------------------------------------------------------------------------------------------
function jd_to_hijri($jd) {
//------------------------------------------------------------------------------------------
$jd = $jd - 1948440 + 10632;
$n = (int)(($jd - 1) / 10631);
$jd = $jd - 10631 * $n + 354;
$j = ((int)((10985 - $jd) / 5316)) *
((int)(50 * $jd / 17719)) +
((int)($jd / 5670)) *
((int)(43 * $jd / 15238));
$jd = $jd - ((int)((30 - $j) / 15)) *
((int)((17719 * $j) / 50)) -
((int)($j / 16)) *
((int)((15238 * $j) / 43)) + 29;
$m = (int)(24 * $jd / 709);
$d = $jd - (int)(709 * $m / 24);
$y = 30*$n + $j - 30;
return array($m, $d, $y);
}
//------------------------------------------------------------------------------------------
function hijri_to_jd($m, $d, $y) {
//------------------------------------------------------------------------------------------
return (int)((11 * $y + 3) / 30) +
354 * $y + 30 * $m -
(int)(($m - 1) / 2) + $d + 1948440 - 385;
}
?>