line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Date::Converter::Gregorian; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1681
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
102
|
|
4
|
2
|
|
|
2
|
|
12
|
use base 'Date::Converter'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
207
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
305
|
|
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 $y2 = Date::Converter::y_common_to_astronomical($y); |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
0
|
my ($y_prime, $m_prime, $d_prime, $j1, $j2, $g); |
24
|
|
|
|
|
|
|
{ |
25
|
2
|
|
|
2
|
|
11
|
use integer; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
14
|
|
|
0
|
|
|
|
|
0
|
|
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
0
|
$y_prime = $y2 + 4716 - int ((14 - $m) / 12); |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
$m_prime = ($m + 9) % 12; |
30
|
0
|
|
|
|
|
0
|
$d_prime = $d - 1; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
0
|
$j1 = (1461 * $y_prime) / 4; |
33
|
0
|
|
|
|
|
0
|
$j2 = (153 * $m_prime + 2) / 5; |
34
|
0
|
|
|
|
|
0
|
$g = 3 * (($y_prime + 184) / 100) / 4 - 38; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
my $jed = $j1 + $j2 + $d_prime - 1401 - $g - 0.5; |
38
|
0
|
|
|
|
|
0
|
$jed += $f; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
0
|
return $jed; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub jed_to_ymdf { |
44
|
34
|
|
|
34
|
0
|
24060
|
my ($jed) = @_; |
45
|
|
|
|
|
|
|
|
46
|
34
|
|
|
|
|
65
|
my $j = int ($jed + 0.5); |
47
|
34
|
|
|
|
|
53
|
my $f = ($jed + 0.5) - $j; |
48
|
|
|
|
|
|
|
|
49
|
34
|
|
|
|
|
41
|
my ($g, $j_prime, $y_prime, $t_prime, $m_prime, $d_prime, $d, $m, $y); |
50
|
|
|
|
|
|
|
{ |
51
|
2
|
|
|
2
|
|
328
|
use integer; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
9
|
|
|
34
|
|
|
|
|
49
|
|
52
|
34
|
|
|
|
|
53
|
$g = 3 * ((4 * $j + 274277) / 146097) / 4 - 38; |
53
|
34
|
|
|
|
|
39
|
$j_prime = $j + 1401 + $g; |
54
|
|
|
|
|
|
|
|
55
|
34
|
|
|
|
|
39
|
$y_prime = (4 * $j_prime + 3) / 1461; |
56
|
34
|
|
|
|
|
51
|
$t_prime = ((4 * $j_prime + 3) % 1461) / 4; |
57
|
34
|
|
|
|
|
43
|
$m_prime = (5 * $t_prime + 2) / 153; |
58
|
34
|
|
|
|
|
36
|
$d_prime = ((5 * $t_prime + 2) % 153) / 5; |
59
|
|
|
|
|
|
|
|
60
|
34
|
|
|
|
|
33
|
$d = $d_prime + 1; |
61
|
34
|
|
|
|
|
41
|
$m = (($m_prime + 2) % 12 ) + 1; |
62
|
34
|
|
|
|
|
48
|
$y = int ($y_prime - 4716 + (14 - $m) / 12); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
34
|
|
|
|
|
128
|
$y = Date::Converter::y_astronomical_to_common($y); |
66
|
|
|
|
|
|
|
|
67
|
34
|
|
|
|
|
291
|
return ($y, $m, $d, $f); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub ymd_check { |
71
|
0
|
|
|
0
|
0
|
|
my ($y_ref, $m_ref, $d_ref) = @_; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
return 1 if ym_check($y_ref, $m_ref); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
day_borrow($y_ref, $m_ref, $d_ref); |
76
|
0
|
|
|
|
|
|
day_carry($y_ref, $m_ref, $d_ref); |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return 0; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub ym_check { |
82
|
0
|
|
|
0
|
0
|
|
my ($y_ref, $m_ref) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
return 1 if y_check($y_ref); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
month_borrow($y_ref, $m_ref); |
87
|
0
|
|
|
|
|
|
month_carry($y_ref, $m_ref); |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return 0; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub y_check { |
93
|
0
|
|
|
0
|
0
|
|
my ($y_ref) = @_; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return $$y_ref == 0; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub day_borrow { |
99
|
0
|
|
|
0
|
0
|
|
my ($y_ref, $m_ref, $d_ref) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
while ($$d_ref <= 0) { |
102
|
0
|
|
|
|
|
|
$$m_ref--; |
103
|
0
|
|
|
|
|
|
month_borrow($y_ref, $m_ref); |
104
|
0
|
|
|
|
|
|
$$d_ref += month_length($$y_ref, $$m_ref); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub day_carry { |
109
|
0
|
|
|
0
|
0
|
|
my ($y_ref, $m_ref, $d_ref) = @_; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $days = month_length($$y_ref, $$m_ref); |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
while ($$d_ref > $days) { |
114
|
0
|
|
|
|
|
|
$$d_ref -= $days; |
115
|
0
|
|
|
|
|
|
$$m_ref++; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$days = month_length($$y_ref, $$m_ref); |
118
|
0
|
|
|
|
|
|
month_carry($y_ref, $m_ref); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub month_borrow { |
123
|
0
|
|
|
0
|
0
|
|
my ($y_ref, $m_ref) = @_; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
while ($$m_ref <= 0) { |
126
|
0
|
|
|
|
|
|
$$m_ref += year_length_months($y_ref); |
127
|
0
|
|
|
|
|
|
$$y_ref--; |
128
|
|
|
|
|
|
|
|
129
|
0
|
0
|
|
|
|
|
$$y_ref = -1 unless $$y_ref; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub month_carry { |
134
|
0
|
|
|
0
|
0
|
|
my ($y_ref, $m_ref) = @_; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
my $months = year_length_months($$y_ref); |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
return if $$m_ref <= $months; |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
$$m_ref -= $months; |
141
|
0
|
|
|
|
|
|
$$y_ref++; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub month_length { |
145
|
0
|
|
|
0
|
0
|
|
my ($y, $m) = @_; |
146
|
|
|
|
|
|
|
|
147
|
0
|
0
|
|
|
|
|
return 0 if ym_check(\$y, \$m); |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
my @mdays = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
my $ret = $mdays[$m - 1]; |
152
|
0
|
0
|
0
|
|
|
|
$ret++ if $m == 2 && year_is_leap($y); |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
return $ret; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub year_length_months { |
158
|
|
|
|
|
|
|
# my ($y) = @_; |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
0
|
0
|
|
return 12; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub year_is_leap { |
164
|
0
|
|
|
0
|
0
|
|
my ($y) = @_; |
165
|
|
|
|
|
|
|
|
166
|
0
|
0
|
|
|
|
|
return 0 unless $y; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
my $y2 = Date::Converter::y_common_to_astronomical($y); |
169
|
|
|
|
|
|
|
|
170
|
0
|
0
|
|
|
|
|
if ($y2 % 400 == 0) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
return 1; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
elsif ($y2 % 100 == 0) { |
174
|
0
|
|
|
|
|
|
return 0; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
elsif ($y2 % 4 == 0) { |
177
|
0
|
|
|
|
|
|
return 1; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
else { |
180
|
0
|
|
|
|
|
|
return 0; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |