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