line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Date::Lima; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
48924
|
use strict; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
303
|
|
4
|
7
|
|
|
7
|
|
42
|
no warnings; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
338
|
|
5
|
7
|
|
|
7
|
|
42
|
use base 'Exporter'; |
|
7
|
|
|
|
|
24
|
|
|
7
|
|
|
|
|
950
|
|
6
|
7
|
|
|
7
|
|
41
|
use Carp; |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
8622
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(beek_date default_conversions nomonth_conversions weeklargest_conversions daysmallest_conversions interval2seconds rev) ] ); |
9
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
10
|
|
|
|
|
|
|
our @EXPORT; |
11
|
|
|
|
|
|
|
our $VERSION = '1.4300'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @conversions; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# sidereal_conversions() {{{ |
16
|
|
|
|
|
|
|
sub sidereal_conversions() { |
17
|
0
|
|
|
0
|
1
|
0
|
my $sidereal_year = 365.256_363_051 * 24 * 60 * 60; |
18
|
0
|
|
|
|
|
0
|
my $sidereal_month = $sidereal_year / 12; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
0
|
@conversions = ( |
21
|
|
|
|
|
|
|
[ y => $sidereal_year ], |
22
|
|
|
|
|
|
|
[ mo => $sidereal_month ], |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
[ w => 7*24*60*60 ], |
25
|
|
|
|
|
|
|
[ d => 24*60*60 ], |
26
|
|
|
|
|
|
|
[ h => 60*60 ], |
27
|
|
|
|
|
|
|
[ m => 60 ], |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
0
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
# }}} |
33
|
|
|
|
|
|
|
# daysmallest_conversions() {{{ |
34
|
|
|
|
|
|
|
sub daysmallest_conversions() { |
35
|
1
|
|
|
1
|
1
|
11
|
@conversions = ( |
36
|
|
|
|
|
|
|
[ y => 365*24*60*60 ], |
37
|
|
|
|
|
|
|
[ mo => 30*24*60*60 ], |
38
|
|
|
|
|
|
|
[ w => 7*24*60*60 ], |
39
|
|
|
|
|
|
|
[ d => 24*60*60 ], |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
3
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
# }}} |
45
|
|
|
|
|
|
|
# default_conversions() {{{ |
46
|
|
|
|
|
|
|
sub default_conversions() { |
47
|
7
|
|
|
7
|
1
|
44
|
@conversions = ( |
48
|
|
|
|
|
|
|
[ y => 365*24*60*60 ], |
49
|
|
|
|
|
|
|
[ mo => 30*24*60*60 ], |
50
|
|
|
|
|
|
|
[ w => 7*24*60*60 ], |
51
|
|
|
|
|
|
|
[ d => 24*60*60 ], |
52
|
|
|
|
|
|
|
[ h => 60*60 ], |
53
|
|
|
|
|
|
|
[ m => 60 ], |
54
|
|
|
|
|
|
|
[ s => 1 ], |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
7
|
|
|
|
|
23
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
# }}} |
60
|
|
|
|
|
|
|
# nomonth_conversions() {{{ |
61
|
|
|
|
|
|
|
sub nomonth_conversions() { |
62
|
1
|
|
|
1
|
1
|
535
|
@conversions = ( |
63
|
|
|
|
|
|
|
[ y => 365*24*60*60 ], |
64
|
|
|
|
|
|
|
[ w => 7*24*60*60 ], |
65
|
|
|
|
|
|
|
[ d => 24*60*60 ], |
66
|
|
|
|
|
|
|
[ h => 60*60 ], |
67
|
|
|
|
|
|
|
[ m => 60 ], |
68
|
|
|
|
|
|
|
[ s => 1 ], |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
3
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
# }}} |
74
|
|
|
|
|
|
|
# weeklargest_conversions() {{{ |
75
|
|
|
|
|
|
|
sub weeklargest_conversions() { |
76
|
1
|
|
|
1
|
1
|
505
|
@conversions = ( |
77
|
|
|
|
|
|
|
[ w => 7*24*60*60 ], |
78
|
|
|
|
|
|
|
[ d => 24*60*60 ], |
79
|
|
|
|
|
|
|
[ h => 60*60 ], |
80
|
|
|
|
|
|
|
[ m => 60 ], |
81
|
|
|
|
|
|
|
[ s => 1 ], |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
|
|
3
|
return; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
# }}} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
default_conversions(); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# _to_secs {{{ |
91
|
|
|
|
|
|
|
sub _to_secs { |
92
|
4
|
|
|
4
|
|
7
|
my $time = shift; |
93
|
|
|
|
|
|
|
|
94
|
4
|
|
|
|
|
7
|
my ($H,$M,$S); |
95
|
|
|
|
|
|
|
|
96
|
4
|
100
|
|
|
|
41
|
if ( ($H, $M, $S) = $time =~ m/^(\d+):(\d{2}):(\d{2})$/ ) { |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
97
|
3
|
|
|
|
|
15
|
return $S |
98
|
|
|
|
|
|
|
+ $M * 60 |
99
|
|
|
|
|
|
|
+ $H * 60 * 60; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} elsif ( ($M, $S) = $time =~ m/^(\d+):(\d{2})$/ ) { |
102
|
1
|
|
|
|
|
7
|
return $S + $M * 60; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} elsif( $time =~ m/^\d+$/ ) { |
105
|
0
|
|
|
|
|
0
|
return $time; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
0
|
croak "time format not understood"; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
# }}} |
111
|
|
|
|
|
|
|
# beek_date($) {{{ |
112
|
|
|
|
|
|
|
sub beek_date($) { |
113
|
29
|
|
|
29
|
1
|
4953
|
my $s = shift; |
114
|
|
|
|
|
|
|
|
115
|
29
|
100
|
|
|
|
112
|
if ( $s =~ m/:/ ) { |
116
|
4
|
|
|
|
|
8
|
$s = eval { _to_secs($s) }; |
|
4
|
|
|
|
|
12
|
|
117
|
|
|
|
|
|
|
|
118
|
4
|
50
|
|
|
|
18
|
croak $@ if $@; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
175
|
|
|
|
|
154
|
my @res = map { |
122
|
29
|
|
|
|
|
53
|
my @r; |
123
|
|
|
|
|
|
|
|
124
|
175
|
100
|
|
|
|
432
|
if( my $v = int( $s / $_->[1] ) ) { |
125
|
78
|
|
|
|
|
105
|
$s -= $v * $_->[1]; |
126
|
78
|
|
|
|
|
1805
|
@r = "$v$_->[0]"; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
175
|
|
|
|
|
305
|
@r } @conversions; |
130
|
|
|
|
|
|
|
|
131
|
29
|
|
|
|
|
47
|
local $" = ""; |
132
|
29
|
50
|
|
|
|
216
|
return @res ? "@res" : "0s"; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
# }}} |
135
|
|
|
|
|
|
|
# {{{ sub rev($) |
136
|
|
|
|
|
|
|
sub rev($) { |
137
|
1
|
|
|
1
|
1
|
1408
|
my $td = shift; |
138
|
|
|
|
|
|
|
|
139
|
1
|
|
|
|
|
4
|
my %conversions = map {(@$_)} @conversions; |
|
7
|
|
|
|
|
24
|
|
140
|
1
|
|
|
|
|
2
|
my $conversions = do { local $" = "|"; my @c = keys %conversions; qr/(?:@c)/ }; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
47
|
|
141
|
|
|
|
|
|
|
|
142
|
1
|
50
|
|
|
|
38
|
croak "interval format not understood" unless $td =~ m/^(?:\d+$conversions)*$/; |
143
|
1
|
|
|
|
|
3
|
my $s = 0; |
144
|
|
|
|
|
|
|
|
145
|
1
|
|
|
|
|
29
|
while( $td =~ m/(\d+)($conversions)/g ) { |
146
|
3
|
|
|
|
|
23
|
$s += $1 * $conversions{$2}; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
1
|
|
|
|
|
8
|
return $s; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
*interval2seconds = \&rev; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# }}} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; |