line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Piece::Over24; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
69247
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
71
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
5
|
2
|
|
|
2
|
|
25
|
use vars qw/$VERSION/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
71
|
|
6
|
2
|
|
|
2
|
|
8
|
use Time::Piece; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
9
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = "0.014"; |
9
|
|
|
|
|
|
|
my $OVER24_OFFSET = '00:00:00'; |
10
|
|
|
|
|
|
|
my $OVER24_BASETIME = localtime; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
16
|
sub import { shift; @_ = ( "Time::Piece", @_ ); goto &Time::Piece::import } |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
8
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package Time::Piece; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub over24 { |
17
|
652
|
|
|
652
|
0
|
1983
|
my ( $self, $time ) = @_; |
18
|
|
|
|
|
|
|
|
19
|
652
|
100
|
|
|
|
2073
|
return $self->from_over24($time) if ($time); |
20
|
2
|
|
|
|
|
6
|
return $self->over24_datetime; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub over24_time { |
24
|
866
|
|
|
866
|
0
|
378593
|
my ( $self, $time ) = @_; |
25
|
866
|
100
|
|
|
|
3070
|
return $self->from_over24_time($time) if ($time); |
26
|
|
|
|
|
|
|
|
27
|
578
|
|
|
|
|
635
|
my $hour; |
28
|
578
|
|
|
|
|
1390
|
( $self, $hour ) = $self->_over24_offset_pattern; |
29
|
578
|
|
|
|
|
1611
|
$hour = sprintf( "%02d", $hour ); |
30
|
578
|
|
|
|
|
2560
|
return $self->strftime("$hour:%M:%S"); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub over24_year { |
34
|
290
|
|
|
290
|
0
|
4956
|
my ($self) = @_; |
35
|
|
|
|
|
|
|
|
36
|
290
|
|
|
|
|
429
|
my $hour; |
37
|
290
|
|
|
|
|
566
|
( $self, $hour ) = $self->_over24_offset_pattern; |
38
|
290
|
|
|
|
|
907
|
return $self->year; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub over24_mon { |
42
|
290
|
|
|
290
|
0
|
137375
|
my ($self) = @_; |
43
|
|
|
|
|
|
|
|
44
|
290
|
|
|
|
|
372
|
my $hour; |
45
|
290
|
|
|
|
|
808
|
( $self, $hour ) = $self->_over24_offset_pattern; |
46
|
290
|
|
|
|
|
893
|
return $self->mon; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub over24_mday { |
50
|
290
|
|
|
290
|
0
|
139449
|
my ($self) = @_; |
51
|
|
|
|
|
|
|
|
52
|
290
|
|
|
|
|
400
|
my $hour; |
53
|
290
|
|
|
|
|
644
|
( $self, $hour ) = $self->_over24_offset_pattern; |
54
|
290
|
|
|
|
|
819
|
return $self->mday; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub over24_hour { |
58
|
300
|
|
|
300
|
0
|
130200
|
my ($self) = @_; |
59
|
300
|
|
|
|
|
413
|
my $hour; |
60
|
300
|
|
|
|
|
564
|
( $self, $hour ) = $self->_over24_offset_pattern; |
61
|
300
|
|
|
|
|
1096
|
return $hour; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub over24_ymd { |
65
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
66
|
0
|
|
|
|
|
0
|
my $hour; |
67
|
0
|
|
|
|
|
0
|
( $self, $hour ) = $self->_over24_offset_pattern; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
return $self->strftime("%Y-%m-%d $hour:%M:%S"); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub over24_datetime { |
73
|
582
|
|
|
582
|
0
|
283648
|
my ( $self, $datetime ) = @_; |
74
|
582
|
100
|
|
|
|
1818
|
return $self->from_over24_datetime($datetime) if ($datetime); |
75
|
|
|
|
|
|
|
|
76
|
294
|
|
|
|
|
406
|
my $hour; |
77
|
294
|
|
|
|
|
583
|
( $self, $hour ) = $self->_over24_offset_pattern(); |
78
|
294
|
|
|
|
|
813
|
$hour = sprintf( "%02d", $hour ); |
79
|
294
|
|
|
|
|
1099
|
return $self->strftime("%Y-%m-%d $hour:%M:%S"); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub from_over24 { |
83
|
938
|
|
|
938
|
0
|
18953
|
my ( $self, $time ) = @_; |
84
|
938
|
50
|
|
|
|
2970
|
if ( $time =~ /^\d\d:\d\d:\d\d$/ ) { |
|
|
100
|
|
|
|
|
|
85
|
0
|
|
|
|
|
0
|
return $self->from_over24_time($time); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
elsif ( $time =~ /^\d\d:\d\d$/ ) { |
88
|
30
|
|
|
|
|
75
|
return $self->from_over24_time( $time . ":00" ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
908
|
|
|
|
|
1763
|
return $self->from_over24_datetime($time); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub from_over24_time { |
96
|
606
|
|
|
606
|
0
|
155133
|
my ( $self, $time ) = @_; |
97
|
606
|
|
|
|
|
1905
|
my $datetime = sprintf("%s %s",$self->ymd,$time); |
98
|
606
|
|
|
|
|
9024
|
return $self->_from_over24($datetime); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub from_over24_datetime { |
102
|
1486
|
|
|
1486
|
0
|
175075
|
my ( $self, $datetime ) = @_; |
103
|
1486
|
|
|
|
|
2973
|
return $self->_from_over24($datetime); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub over24_offset { |
107
|
9670
|
|
|
9670
|
0
|
204305
|
my ( $self, $offset ) = @_; |
108
|
9670
|
100
|
|
|
|
19518
|
if ($offset) { |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#just time |
111
|
2651
|
50
|
|
|
|
12150
|
if ( $offset =~ /^\d\d?$/ ) { |
|
|
50
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
$offset = sprintf( "%02d:00:00", $offset ); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
elsif ( $offset =~ /^\d\d?:\d\d$/ ) { |
115
|
0
|
|
|
|
|
0
|
$offset .= ":00"; |
116
|
|
|
|
|
|
|
} |
117
|
2651
|
|
|
|
|
3647
|
$OVER24_OFFSET = $offset; |
118
|
|
|
|
|
|
|
} |
119
|
9670
|
|
|
|
|
37841
|
return $OVER24_OFFSET; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub is_during { |
123
|
892
|
|
|
892
|
0
|
231530
|
my $self = shift; |
124
|
892
|
|
50
|
|
|
2470
|
my $start_time = shift || die "need start_time"; |
125
|
892
|
|
50
|
|
|
30026
|
my $end_time = shift || die "need end_time"; |
126
|
892
|
|
66
|
|
|
35689
|
my $check_time = shift || $self; |
127
|
|
|
|
|
|
|
|
128
|
892
|
|
|
|
|
37722
|
my $buf_offset = $self->over24_offset; |
129
|
892
|
|
|
|
|
1734
|
$self->over24_offset("00:00:00"); |
130
|
|
|
|
|
|
|
|
131
|
892
|
50
|
|
|
|
2365
|
unless ( ( ref($start_time) eq "Time::Piece" ) == |
132
|
|
|
|
|
|
|
( ref($end_time) eq "Time::Piece" ) ) |
133
|
|
|
|
|
|
|
{ |
134
|
0
|
|
|
|
|
0
|
die "start_time and end_time is different object"; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
892
|
50
|
|
|
|
2281
|
unless ( length($start_time) == length($end_time) ) { |
138
|
0
|
|
|
|
|
0
|
die "start_time and end_time is different format"; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
892
|
|
|
|
|
28966
|
my $div = 0; |
142
|
892
|
100
|
|
|
|
2056
|
unless ( ref($check_time) eq "Time::Piece" ) { |
143
|
28
|
|
|
|
|
32
|
my $buf = $check_time; |
144
|
28
|
|
|
|
|
55
|
$check_time = $self->over24($check_time); |
145
|
28
|
100
|
|
|
|
3306
|
if ( $buf =~ /^\d\d:\d\d$/ ) { |
146
|
10
|
|
|
|
|
20
|
$div = int( $check_time->over24_hour / 24 ); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
892
|
|
|
|
|
901
|
my ( $start_t, $end_t ); |
151
|
892
|
100
|
|
|
|
1642
|
if ( ref($start_time) eq "Time::Piece" ) { |
152
|
581
|
|
|
|
|
741
|
$start_t = $start_time; |
153
|
581
|
|
|
|
|
828
|
$end_t = $end_time; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
else { |
156
|
311
|
|
|
|
|
352
|
my $t = $check_time; |
157
|
311
|
|
|
|
|
533
|
my $div_time = 86400 * $div; |
158
|
311
|
|
|
|
|
844
|
$start_t = $t->over24($start_time) - $div_time; |
159
|
311
|
|
|
|
|
47850
|
$end_t = $t->over24($end_time) - $div_time; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
892
|
100
|
100
|
|
|
52540
|
my $rtn = ( ( $start_t <= $check_time ) && ( $check_time <= $end_t ) ) |
163
|
|
|
|
|
|
|
? '1' |
164
|
|
|
|
|
|
|
: undef; |
165
|
892
|
|
|
|
|
21816
|
$self->over24_offset($buf_offset); |
166
|
892
|
|
|
|
|
3529
|
return $rtn; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub _over24_offset_object { |
170
|
2042
|
|
|
2042
|
|
2438
|
my ($self) = @_; |
171
|
|
|
|
|
|
|
|
172
|
2042
|
100
|
|
|
|
3192
|
my $ymd = |
173
|
|
|
|
|
|
|
$self->over24_offset eq "00:00:00" ? $OVER24_BASETIME->ymd : $self->ymd; |
174
|
2042
|
|
|
|
|
27045
|
return $self->strptime( sprintf( "%s %s", $ymd, $self->over24_offset ), |
175
|
|
|
|
|
|
|
'%Y-%m-%d %T' ); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub _over24_offset_pattern { |
179
|
2042
|
|
|
2042
|
|
2648
|
my ($self) = @_; |
180
|
2042
|
|
|
|
|
4994
|
my $hour = $self->hour; |
181
|
2042
|
|
|
|
|
9505
|
my $ts = $self - $self->_over24_offset_object; |
182
|
|
|
|
|
|
|
|
183
|
2042
|
100
|
|
|
|
225177
|
my $div = $self->over24_offset eq "00:00:00" ? int( $ts->days ) : 0; |
184
|
2042
|
100
|
|
|
|
13917
|
$div += 1 if ( $ts < 0 ); |
185
|
2042
|
100
|
|
|
|
30928
|
if ($div > 0) { |
186
|
682
|
|
|
|
|
2030
|
$self -= 86400 * $div; |
187
|
682
|
|
|
|
|
38556
|
$hour += 24 * $div; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
2042
|
|
|
|
|
5621
|
return ( $self, $hour ); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub _from_over24 { |
194
|
2092
|
|
|
2092
|
|
2997
|
my ( $self, $datetime ) = @_; |
195
|
|
|
|
|
|
|
|
196
|
2092
|
|
|
|
|
12599
|
my @hms = split /[\s:]/, $datetime; |
197
|
2092
|
|
|
|
|
4023
|
my $date = shift @hms; |
198
|
2092
|
|
|
|
|
8438
|
my $time = join ":", sprintf( "%02d",$hms[0] % 24 ),$hms[1],$hms[2]; |
199
|
|
|
|
|
|
|
|
200
|
2092
|
|
|
|
|
11882
|
$OVER24_BASETIME = |
201
|
|
|
|
|
|
|
$self->strptime( sprintf( "%s %s", $date, $time ), "%Y-%m-%d %T" ); |
202
|
|
|
|
|
|
|
|
203
|
2092
|
|
|
|
|
61319
|
return $OVER24_BASETIME + int( $hms[0] / 24 ) * 86400; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
1; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
__END__ |