line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Calendar::Any::Gregorian; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Calendar::Any::Gregorian::VERSION = '0.5'; |
4
|
|
|
|
|
|
|
} |
5
|
5
|
|
|
5
|
|
25651
|
use base 'Calendar::Any::Julian'; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
3094
|
|
6
|
5
|
|
|
5
|
|
26
|
use POSIX qw/ceil/; |
|
5
|
|
|
|
|
29
|
|
|
5
|
|
|
|
|
36
|
|
7
|
|
|
|
|
|
|
our $default_format = "%D"; |
8
|
|
|
|
|
|
|
my @MONTH_DAYS = Calendar::Any::Julian::MONTH_DAYS(); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub from_absolute { |
11
|
5
|
|
|
5
|
|
505
|
use integer; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
19
|
|
12
|
37
|
|
|
37
|
0
|
44
|
my $self = shift; |
13
|
37
|
|
|
|
|
46
|
my $d0 = shift; |
14
|
37
|
|
|
|
|
406
|
$self->{absolute} = $d0; |
15
|
37
|
|
|
|
|
50
|
$d0--; |
16
|
37
|
|
|
|
|
41
|
my ($n400, $d1, $n100, $d2, $n4, $d3, $n1, $day, $year, $month); |
17
|
37
|
|
|
|
|
45
|
$n400 = $d0 / 146097; |
18
|
37
|
|
|
|
|
95
|
$d1 = $d0 % 146097; |
19
|
37
|
|
|
|
|
44
|
$n100 = $d1 / 36524; |
20
|
37
|
|
|
|
|
41
|
$d2 = $d1 % 36524; |
21
|
37
|
|
|
|
|
47
|
$n4 = $d2 / 1461; |
22
|
37
|
|
|
|
|
35
|
$d3 = $d2 % 1461; |
23
|
37
|
|
|
|
|
34
|
$n1 = $d3 / 365; |
24
|
37
|
|
|
|
|
85
|
$day = $d3 % 365 + 1; |
25
|
37
|
|
|
|
|
59
|
$year = 400*$n400 + 100*$n100 + 4*$n4 + $n1; |
26
|
37
|
50
|
33
|
|
|
159
|
if ( $n100==4 || $n1==4 ) { |
27
|
0
|
|
|
|
|
0
|
$month = 12; |
28
|
0
|
|
|
|
|
0
|
$day = 31; |
29
|
|
|
|
|
|
|
} else { |
30
|
37
|
|
|
|
|
40
|
$year++; |
31
|
37
|
|
|
|
|
158
|
$month = ceil($day/31); |
32
|
37
|
50
|
|
|
|
73
|
my $leap = (_is_leap_year($year) ? 1 : 0); |
33
|
37
|
100
|
|
|
|
140
|
while ( $day > $MONTH_DAYS[$month]+($month>1?$leap:0) ) { |
34
|
37
|
|
|
|
|
116
|
$month++; |
35
|
|
|
|
|
|
|
} |
36
|
37
|
100
|
|
|
|
85
|
$day = $day-$MONTH_DAYS[$month-1]-($month>2?$leap:0); |
37
|
|
|
|
|
|
|
} |
38
|
37
|
|
|
|
|
64
|
$self->{year} = $year; |
39
|
37
|
|
|
|
|
78
|
$self->{month} = $month; |
40
|
37
|
|
|
|
|
49
|
$self->{day} = $day; |
41
|
37
|
|
|
|
|
155
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub absolute_date { |
45
|
5
|
|
|
5
|
|
1407
|
use integer; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
18
|
|
46
|
34
|
|
|
34
|
0
|
56
|
my $self = shift; |
47
|
34
|
100
|
|
|
|
106
|
if ( exists $self->{absolute} ) { |
48
|
30
|
|
|
|
|
134
|
return $self->{absolute}; |
49
|
|
|
|
|
|
|
} |
50
|
4
|
|
|
|
|
30
|
$self->assert_date(); |
51
|
4
|
|
|
|
|
15
|
my $year = $self->year; |
52
|
4
|
50
|
|
|
|
19
|
if ( $year > 0 ) { |
53
|
4
|
|
|
|
|
10
|
my $offset = $year -1; |
54
|
4
|
|
|
|
|
24
|
$self->{absolute} = $self->day_of_year + 365*$offset + $offset/4 - $offset/100 + $offset/400; |
55
|
|
|
|
|
|
|
} else { |
56
|
0
|
|
|
|
|
0
|
my $offset = abs($year+1); |
57
|
0
|
|
|
|
|
0
|
$self->{absolute} = -($self->day_of_year + 365*$offset + $offset/4 - $offset/100 + $offset/400 + _day_of_year(12, 31, -1)); |
58
|
|
|
|
|
|
|
} |
59
|
4
|
|
|
|
|
15
|
return $self->{absolute}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub is_leap_year { |
63
|
1
|
|
|
1
|
1
|
4
|
return _is_leap_year(shift->year); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
#========================================================== |
67
|
|
|
|
|
|
|
# Private functions |
68
|
|
|
|
|
|
|
#========================================================== |
69
|
|
|
|
|
|
|
sub _is_leap_year { |
70
|
38
|
|
|
38
|
|
47
|
my $year = shift; |
71
|
38
|
50
|
|
|
|
80
|
if ( $year < 0 ) { |
72
|
0
|
|
|
|
|
0
|
$year = abs($year) - 1; |
73
|
|
|
|
|
|
|
} |
74
|
38
|
50
|
0
|
|
|
151
|
($year%4 == 0) && ($year%100>0 || ($year%400 == 0)); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
__END__ |