line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Date::Converter::Islamic; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1756
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
4
|
1
|
|
|
1
|
|
6
|
use base 'Date::Converter'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
100
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
154
|
|
7
|
|
|
|
|
|
|
$VERSION = 1.1; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# E G Richards, |
10
|
|
|
|
|
|
|
# Algorithm E, |
11
|
|
|
|
|
|
|
# Mapping Time, The Calendar and Its History, |
12
|
|
|
|
|
|
|
# Oxford, 1999, pages 323-325. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub ymdf_to_jed { |
15
|
0
|
|
|
0
|
0
|
0
|
my ($y, $m, $d, $f) = @_; |
16
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
0
|
$f = 0 unless defined $f; |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
0
|
return -1 if ymd_check(\$y, \$m, \$d); |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
0
|
my ($y_prime, $m_prime, $d_prime, $j1, $j2); |
22
|
|
|
|
|
|
|
{ |
23
|
1
|
|
|
1
|
|
8
|
use integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
|
0
|
|
|
|
|
0
|
|
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
0
|
$y_prime = $y + 5519 - (12 - $m) / 12; |
26
|
0
|
|
|
|
|
0
|
$m_prime = ($m + 11) % 12; |
27
|
0
|
|
|
|
|
0
|
$d_prime = $d - 1; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
$j1 = (10631 * $y_prime + 14) / 30; |
30
|
0
|
|
|
|
|
0
|
$j2 = (2951 * $m_prime + 51) / 100; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
my $jed = ($j1 + $j2 + $d_prime - 7665) - 0.5; |
34
|
0
|
|
|
|
|
0
|
$jed += $f; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
return $jed; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub jed_to_ymdf { |
40
|
32
|
|
|
32
|
0
|
15526
|
my ($jed) = @_; |
41
|
|
|
|
|
|
|
|
42
|
32
|
|
|
|
|
58
|
my $j = int ($jed + 0.5); |
43
|
32
|
|
|
|
|
53
|
my $f = ($jed + 0.5) - $j; |
44
|
|
|
|
|
|
|
|
45
|
32
|
|
|
|
|
34
|
my ($j_prime, $y_prime, $t_prime, $m_prime, $d_prime, $y, $m, $d); |
46
|
|
|
|
|
|
|
{ |
47
|
1
|
|
|
1
|
|
212
|
use integer; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
|
32
|
|
|
|
|
32
|
|
48
|
|
|
|
|
|
|
|
49
|
32
|
|
|
|
|
39
|
$j_prime = $j + 7665; |
50
|
|
|
|
|
|
|
|
51
|
32
|
|
|
|
|
34
|
$y_prime = (30 * $j_prime + 15) / 10631; |
52
|
32
|
|
|
|
|
46
|
$t_prime = ((30 * $j_prime + 15) % 10631) / 30; |
53
|
32
|
|
|
|
|
35
|
$m_prime = (100 * $t_prime + 10) / 2951; |
54
|
32
|
|
|
|
|
52
|
$d_prime = ((100 * $t_prime + 10) % 2951) / 100; |
55
|
|
|
|
|
|
|
|
56
|
32
|
|
|
|
|
30
|
$d = $d_prime + 1; |
57
|
32
|
|
|
|
|
32
|
$m = ($m_prime % 12) + 1; |
58
|
32
|
|
|
|
|
51
|
$y = $y_prime - 5519 + (12 - $m) / 12; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
32
|
|
|
|
|
263
|
return ($y, $m, $d, $f); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub ymd_check { |
65
|
0
|
|
|
0
|
0
|
|
my ($y_ref, $m_ref, $d_ref) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
return 1 if $$y_ref <= 0; |
68
|
0
|
0
|
|
|
|
|
return 1 if ym_check($y_ref, $m_ref); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
day_borrow($y_ref, $m_ref, $d_ref); |
71
|
0
|
|
|
|
|
|
day_carry($y_ref, $m_ref, $d_ref); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return 0; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub ym_check { |
77
|
0
|
|
|
0
|
0
|
|
my ($y_ref, $m_ref) = @_; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
return 1 if y_check($y_ref); |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
month_borrow($y_ref, $m_ref); |
82
|
0
|
|
|
|
|
|
month_carry($y_ref, $m_ref); |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return 0; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub y_check { |
88
|
0
|
|
|
0
|
0
|
|
my ($y_ref) = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return !($$y_ref > 0); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub month_borrow { |
94
|
0
|
|
|
0
|
0
|
|
my ($y_ref, $m_ref) = @_; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
while ($$m_ref <= 0) { |
97
|
0
|
|
|
|
|
|
$$m_ref += year_length_months($$y_ref); |
98
|
0
|
|
|
|
|
|
$$y_ref--; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub month_carry { |
103
|
0
|
|
|
0
|
0
|
|
my ($y_ref, $m_ref) = @_; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $months = year_length_months($$y_ref); |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
return if $$m_ref <= $months; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$$m_ref -= $months; |
110
|
0
|
|
|
|
|
|
$$y_ref++; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub day_borrow { |
114
|
0
|
|
|
0
|
0
|
|
my ($y_ref, $m_ref, $d_ref) = @_; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
while ($$d_ref <= 0) { |
117
|
0
|
|
|
|
|
|
$$m_ref--; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
month_borrow($y_ref, $m_ref); |
120
|
0
|
|
|
|
|
|
$$d_ref += month_length($$y_ref, $$m_ref); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub day_carry { |
125
|
0
|
|
|
0
|
0
|
|
my ($y_ref, $m_ref, $d_ref) = @_; |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my $days = month_length($$y_ref, $$m_ref); |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
while ($$d_ref > $days) { |
130
|
0
|
|
|
|
|
|
$$d_ref -= $days; |
131
|
0
|
|
|
|
|
|
$$m_ref++; |
132
|
0
|
|
|
|
|
|
$days = month_length($$y_ref, $$m_ref); |
133
|
0
|
|
|
|
|
|
month_carry($y_ref, $m_ref); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub year_length_months { |
138
|
|
|
|
|
|
|
# my $y = shift; |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
0
|
0
|
|
return 12; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub month_length { |
144
|
0
|
|
|
0
|
0
|
|
my ($y, $m) = @_; |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my @mdays = (30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29); |
147
|
|
|
|
|
|
|
|
148
|
0
|
0
|
|
|
|
|
return 0 if ym_check(\$y, \$m); |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
my $ret = $mdays[$m - 1]; |
151
|
|
|
|
|
|
|
|
152
|
0
|
0
|
0
|
|
|
|
$ret++ if $m == 12 && year_is_leap($y); |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
return $ret; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub year_is_leap { |
158
|
0
|
|
|
0
|
0
|
|
my $y = shift; |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
return Date::Convert::i_modp (11 * $y + 14, 30) < 11; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1; |