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