line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Calendar::Any; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Calendar::Any::VERSION = '0.5'; |
4
|
|
|
|
|
|
|
} |
5
|
6
|
|
|
6
|
|
24655
|
use Carp; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
1036
|
|
6
|
|
|
|
|
|
|
use overload |
7
|
0
|
0
|
|
0
|
|
0
|
'<=>' => sub { $_[0]->absolute_date <=> (ref $_[1] ? $_[1]->absolute_date : $_[1]) }, |
8
|
6
|
|
|
|
|
85
|
'+' => \&add, |
9
|
|
|
|
|
|
|
'-' => \&substract, |
10
|
|
|
|
|
|
|
'""' => \&date_string, |
11
|
6
|
|
|
6
|
|
26663
|
'0+' => \&absolute_date; |
|
6
|
|
|
|
|
7167
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
9
|
|
|
9
|
1
|
23
|
my $_class = shift; |
15
|
9
|
|
33
|
|
|
40
|
my $class = ref $_class || $_class; |
16
|
9
|
|
|
|
|
17
|
my $self = {}; |
17
|
9
|
|
|
|
|
17
|
bless $self, $class; |
18
|
9
|
50
|
|
|
|
29
|
if ( @_ ) { |
19
|
9
|
|
|
|
|
121
|
$self->{absolute} = shift; |
20
|
|
|
|
|
|
|
} |
21
|
9
|
|
|
|
|
47
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new_from_Astro { |
25
|
8
|
|
|
8
|
1
|
52
|
my ($self, $days) = @_; |
26
|
8
|
|
|
|
|
33
|
return $self->new($days - 1721424.5); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub absolute_date { |
30
|
11
|
|
|
11
|
0
|
992
|
return shift->{absolute}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub astro_date { |
34
|
27
|
|
|
27
|
1
|
82
|
return shift->absolute_date + 1721424.5; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub today { |
38
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
39
|
0
|
|
|
|
|
0
|
my @time = localtime; |
40
|
0
|
|
|
|
|
0
|
my $date = $self->new_from_Gregorian($time[4]+1, $time[3], $time[5]+1900); |
41
|
0
|
|
|
|
|
0
|
return $self->new($date->absolute_date); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#{{{ Format functions |
45
|
|
|
|
|
|
|
our @weekday_name = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); |
46
|
|
|
|
|
|
|
our @month_name = qw(January February March April May June July August September October November December); |
47
|
|
|
|
|
|
|
our $default_format = "%A"; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub year { |
50
|
68
|
|
|
68
|
1
|
1801
|
return shift->{year}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub month { |
54
|
35
|
|
|
35
|
1
|
173
|
return shift->{month}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub day { |
58
|
31
|
|
|
31
|
1
|
153
|
return shift->{day}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub weekday { |
62
|
0
|
|
|
0
|
1
|
0
|
return shift->{absolute} % 7; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub weekday_name { |
66
|
0
|
|
|
0
|
1
|
0
|
return $weekday_name[shift->weekday]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub month_name { |
70
|
0
|
|
|
0
|
1
|
0
|
return $month_name[shift->month-1]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub date_string { |
74
|
5
|
|
|
5
|
0
|
1554
|
my $self = shift; |
75
|
6
|
|
|
6
|
|
3210
|
no strict; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
3285
|
|
76
|
5
|
|
33
|
|
|
23
|
my $fmt = shift || ${(ref $self||$self)."::default_format"} || $default_format; |
77
|
5
|
|
|
|
|
46
|
$fmt =~ s/ |
78
|
|
|
|
|
|
|
%(O?[%a-zA-Z]) |
79
|
|
|
|
|
|
|
/ |
80
|
5
|
|
50
|
0
|
|
106
|
($self->can("format_$1") || sub { $1 })->($self); |
|
0
|
|
|
|
|
0
|
|
81
|
|
|
|
|
|
|
/sgeox; |
82
|
5
|
|
|
|
|
43
|
return $fmt; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
0
|
0
|
0
|
sub format_d { sprintf("%02d", shift->day) } |
86
|
0
|
|
|
0
|
0
|
0
|
sub format_m { sprintf("%02d", shift->month) } |
87
|
1
|
|
|
1
|
0
|
5
|
sub format_A { shift->absolute_date } |
88
|
0
|
|
|
0
|
0
|
0
|
sub format_w { shift->weekday } |
89
|
0
|
|
|
0
|
0
|
0
|
sub format_W { shift->weekday_name } |
90
|
0
|
|
|
0
|
0
|
0
|
sub format_M { shift->month_name } |
91
|
0
|
|
|
0
|
0
|
0
|
sub format_Y { shift->year } |
92
|
|
|
|
|
|
|
sub format_D { |
93
|
4
|
|
|
4
|
0
|
9
|
my $self = shift; |
94
|
4
|
|
|
|
|
23
|
return join("/", map { sprintf "%02d", $_ } $self->month, $self->day, $self->year); |
|
12
|
|
|
|
|
59
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
sub format_F { |
97
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
98
|
0
|
|
|
|
|
0
|
return join("-", map { sprintf "%02d", $_ } $self->year, $self->month, $self->day); |
|
0
|
|
|
|
|
0
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
#}}} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#{{{ Overload Operators |
103
|
|
|
|
|
|
|
sub substract { |
104
|
0
|
|
|
0
|
0
|
0
|
my ($self, $operand) = @_; |
105
|
0
|
0
|
|
|
|
0
|
if ( ref $operand ) { |
106
|
0
|
|
|
|
|
0
|
return $self->absolute_date - $operand->absolute_date; |
107
|
|
|
|
|
|
|
} else { |
108
|
0
|
|
|
|
|
0
|
return $self->new($self->absolute_date-$operand); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub add { |
113
|
0
|
|
|
0
|
0
|
0
|
my ($self, $operand) = @_; |
114
|
0
|
0
|
|
|
|
0
|
confess "operand must be numeric!\n" if ref $operand; |
115
|
0
|
|
|
|
|
0
|
$self->new($self->absolute_date + $operand); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
#}}} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub AUTOLOAD { |
120
|
6
|
|
|
6
|
|
34
|
no strict 'refs'; |
|
6
|
|
|
|
|
1318
|
|
|
6
|
|
|
|
|
2650
|
|
121
|
4
|
|
|
4
|
|
11
|
our ($AUTOLOAD); |
122
|
4
|
|
|
|
|
25
|
(my $subname = $AUTOLOAD) =~ s/.*:://; |
123
|
4
|
100
|
|
|
|
34
|
if ( $AUTOLOAD =~ /::new_from_(\w+)/ ) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
124
|
1
|
|
|
|
|
4
|
my $module = "Calendar::Any::" . $1; |
125
|
1
|
|
|
|
|
67
|
eval("require $module"); |
126
|
1
|
50
|
|
|
|
10
|
if ( $@ ) { |
127
|
0
|
|
|
|
|
0
|
die "Can't load module $module: $@!\n" |
128
|
|
|
|
|
|
|
} |
129
|
1
|
|
|
|
|
11
|
my $sub = *{$subname} = sub { |
130
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
131
|
1
|
|
|
|
|
10
|
return $module->new(@_); |
132
|
1
|
|
|
|
|
8
|
}; |
133
|
1
|
|
|
|
|
8
|
goto &$sub; |
134
|
|
|
|
|
|
|
} elsif ( $AUTOLOAD =~ /::to_(\w+)/ ) { |
135
|
3
|
|
|
|
|
17
|
my $module = "Calendar::Any::" . $1; |
136
|
3
|
|
|
|
|
317
|
eval("require $module"); |
137
|
3
|
50
|
|
|
|
16
|
if ( $@ ) { |
138
|
0
|
|
|
|
|
0
|
die "Can't load module $module: $@!\n" |
139
|
|
|
|
|
|
|
} |
140
|
3
|
|
|
|
|
32
|
my $sub = *{$subname} = sub { |
141
|
7
|
|
|
7
|
|
24
|
$_[0] = $module->new($_[0]->absolute_date); |
142
|
7
|
|
|
|
|
46
|
return $_[0]; |
143
|
3
|
|
|
|
|
15
|
}; |
144
|
3
|
|
|
|
|
24
|
goto &$sub; |
145
|
|
|
|
|
|
|
} elsif ( $AUTOLOAD =~ /DESTROY/) { |
146
|
|
|
|
|
|
|
} else { |
147
|
0
|
|
|
|
|
|
die "Unknown function $AUTOLOAD\n"; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
__END__ |