line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::List; |
2
|
7
|
|
|
7
|
|
134265
|
use 5.008_001; |
|
7
|
|
|
|
|
26
|
|
|
7
|
|
|
|
|
251
|
|
3
|
7
|
|
|
7
|
|
40
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
227
|
|
4
|
7
|
|
|
7
|
|
33
|
use warnings; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
232
|
|
5
|
7
|
|
|
7
|
|
6991
|
use Time::Piece; |
|
7
|
|
|
|
|
105492
|
|
|
7
|
|
|
|
|
40
|
|
6
|
7
|
|
|
7
|
|
4746
|
use Time::List::Rows; |
|
7
|
|
|
|
|
25
|
|
|
7
|
|
|
|
|
209
|
|
7
|
7
|
|
|
7
|
|
43
|
use Class::Accessor::Lite; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
36
|
|
8
|
7
|
|
|
7
|
|
304
|
use Time::List::Constant; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
102
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $unit_time = { |
13
|
|
|
|
|
|
|
DAY() => 3600 * 24 , |
14
|
|
|
|
|
|
|
WEEK() => 3600 * 24 * 7 , |
15
|
|
|
|
|
|
|
HOUR() => 3600 , |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %DEFAULTS = ( |
19
|
|
|
|
|
|
|
time_unit => DAY() , |
20
|
|
|
|
|
|
|
output_type => ARRAY() , |
21
|
|
|
|
|
|
|
limit_rows => 0 , |
22
|
|
|
|
|
|
|
input_strftime_form => '%Y-%m-%d %H:%M:%S', |
23
|
|
|
|
|
|
|
output_strftime_form => '%Y-%m-%d %H:%M:%S', |
24
|
|
|
|
|
|
|
show_end_time => 0 , |
25
|
|
|
|
|
|
|
boundary_included => 1 , |
26
|
|
|
|
|
|
|
end_time_separate_chars => '~' , |
27
|
|
|
|
|
|
|
create_summary => 0 , |
28
|
|
|
|
|
|
|
summary_key_name => "summary" |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Class::Accessor::Lite->mk_accessors(keys %DEFAULTS); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
8
|
|
|
8
|
1
|
19
|
my $class = shift; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
my $self = bless { |
37
|
|
|
|
|
|
|
%DEFAULTS, |
38
|
8
|
50
|
|
|
|
124
|
@_ == 1 ? %{ $_[0] } : @_, |
39
|
|
|
|
|
|
|
}, $class; |
40
|
8
|
|
|
|
|
29
|
$self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub get_list{ |
44
|
24
|
|
|
24
|
1
|
12481
|
my ($self , $start_time , $end_time) = @_; |
45
|
|
|
|
|
|
|
|
46
|
24
|
|
|
|
|
75
|
my $output_type = $self->output_type; |
47
|
24
|
|
|
|
|
156
|
my $time_unit = $self->time_unit; |
48
|
24
|
|
|
|
|
119
|
my $input_strftime_form = $self->input_strftime_form; |
49
|
24
|
|
|
|
|
119
|
my $output_strftime_form = $self->output_strftime_form; |
50
|
|
|
|
|
|
|
|
51
|
24
|
|
|
|
|
96
|
my $time_array = []; |
52
|
24
|
|
|
|
|
70
|
my $show_end_time = $self->show_end_time; |
53
|
24
|
100
|
|
|
|
132
|
if($time_unit == MONTH){ |
54
|
11
|
|
|
|
|
45
|
my $start_tp = Time::Piece->strptime($start_time , $input_strftime_form); |
55
|
11
|
|
|
|
|
319
|
my $end_tp = Time::Piece->strptime($end_time , $input_strftime_form); |
56
|
|
|
|
|
|
|
|
57
|
11
|
|
|
|
|
314
|
my ($start_year , $start_month) = ($start_tp->strftime('%Y') , $start_tp->strftime('%m')); |
58
|
|
|
|
|
|
|
|
59
|
11
|
|
|
|
|
621
|
my ($end_year , $end_month) = ($end_tp->strftime('%Y') , $end_tp->strftime('%m')); |
60
|
|
|
|
|
|
|
|
61
|
11
|
50
|
|
|
|
207
|
if($self->boundary_included){ |
62
|
11
|
|
100
|
|
|
134
|
while($start_year < $end_year || ($start_year == $end_year && $start_month <= $end_month)){ |
|
|
|
66
|
|
|
|
|
63
|
41
|
100
|
|
|
|
68
|
if($show_end_time){ |
64
|
20
|
|
|
|
|
78
|
my ( $next_year , $next_month) = ($start_year , $start_month); |
65
|
20
|
100
|
|
|
|
43
|
if(++$next_month > 12){ |
66
|
2
|
|
|
|
|
3
|
$next_month = 1; |
67
|
2
|
|
|
|
|
3
|
$next_year++; |
68
|
|
|
|
|
|
|
} |
69
|
20
|
|
|
|
|
73
|
push @$time_array , |
70
|
|
|
|
|
|
|
Time::Piece->strptime("$start_year:$start_month" , '%Y:%m')->strftime('%s') |
71
|
|
|
|
|
|
|
. "\t" |
72
|
|
|
|
|
|
|
. (Time::Piece->strptime("$next_year:$next_month" , '%Y:%m')->strftime('%s') - 1); |
73
|
|
|
|
|
|
|
}else{ |
74
|
21
|
|
|
|
|
88
|
push @$time_array , Time::Piece->strptime("$start_year:$start_month" , '%Y:%m')->strftime('%s'); |
75
|
|
|
|
|
|
|
} |
76
|
41
|
100
|
|
|
|
1885
|
if(++$start_month > 12){ |
77
|
2
|
|
|
|
|
3
|
$start_month = 1; |
78
|
2
|
|
|
|
|
12
|
$start_year ++; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
}else{ |
82
|
0
|
|
0
|
|
|
0
|
while($start_year < $end_year || $start_month < $end_month){ |
83
|
0
|
0
|
|
|
|
0
|
if($show_end_time){ |
84
|
0
|
|
|
|
|
0
|
my ( $next_year , $next_month) = ($start_year , $start_month); |
85
|
0
|
0
|
|
|
|
0
|
if(++$next_month > 12){ |
86
|
0
|
|
|
|
|
0
|
$next_month = 1; |
87
|
0
|
|
|
|
|
0
|
$next_year++; |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
0
|
push @$time_array , |
90
|
|
|
|
|
|
|
Time::Piece->strptime("$start_year:$start_month" , '%Y:%m')->strftime('%s') |
91
|
|
|
|
|
|
|
. "\t" |
92
|
|
|
|
|
|
|
. (Time::Piece->strptime("$next_year:$next_month" , '%Y:%m')->strftime('%s') - 1); |
93
|
|
|
|
|
|
|
}else{ |
94
|
0
|
|
|
|
|
0
|
push @$time_array , Time::Piece->strptime("$start_year:$start_month" , '%Y:%m')->strftime('%s'); |
95
|
|
|
|
|
|
|
} |
96
|
0
|
0
|
|
|
|
0
|
if(++$start_month > 12){ |
97
|
0
|
|
|
|
|
0
|
$start_month = 1; |
98
|
0
|
|
|
|
|
0
|
$start_year ++; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
}else{ |
104
|
13
|
|
|
|
|
32
|
my $unit_time_value = $unit_time->{$time_unit}; |
105
|
13
|
50
|
|
|
|
33
|
die 'set time unit' unless $unit_time_value; |
106
|
13
|
|
|
|
|
64
|
my $start_tp_time = Time::Piece->strptime($start_time , $input_strftime_form)->strftime('%s'); |
107
|
13
|
100
|
|
|
|
946
|
my $start_posix_time = Time::Piece->strptime( |
108
|
|
|
|
|
|
|
localtime($start_tp_time + $unit_time_value - 1 , '%s')->strftime($time_unit == HOUR() ? '%Y-%m-%d %H:00:00' : '%Y-%m-%d 00:00:00') , |
109
|
|
|
|
|
|
|
'%Y-%m-%d %H:%M:%S') |
110
|
|
|
|
|
|
|
->strftime('%s'); |
111
|
13
|
|
|
|
|
587
|
my $end_posix_time = Time::Piece->strptime($end_time , $input_strftime_form)->strftime('%s'); |
112
|
|
|
|
|
|
|
|
113
|
13
|
100
|
|
|
|
459
|
if($self->boundary_included){ |
114
|
12
|
100
|
|
|
|
68
|
if($show_end_time){ |
115
|
4
|
|
|
|
|
18
|
push @$time_array , |
116
|
|
|
|
|
|
|
$start_posix_time |
117
|
|
|
|
|
|
|
. "\t" |
118
|
|
|
|
|
|
|
. ($start_posix_time + $unit_time_value - 1); |
119
|
|
|
|
|
|
|
}else{ |
120
|
8
|
|
|
|
|
16
|
push @$time_array , $start_posix_time; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
12
|
|
|
|
|
35
|
while($start_posix_time < $end_posix_time){ |
124
|
164
|
|
|
|
|
167
|
$start_posix_time += $unit_time_value; |
125
|
164
|
100
|
|
|
|
230
|
if($show_end_time){ |
126
|
36
|
|
|
|
|
119
|
push @$time_array , |
127
|
|
|
|
|
|
|
$start_posix_time |
128
|
|
|
|
|
|
|
. "\t" |
129
|
|
|
|
|
|
|
. ($start_posix_time + $unit_time_value - 1); |
130
|
|
|
|
|
|
|
}else{ |
131
|
128
|
|
|
|
|
264
|
push @$time_array , $start_posix_time; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
}else{ |
135
|
1
|
|
|
|
|
10
|
while($start_posix_time < $end_posix_time){ |
136
|
24
|
50
|
|
|
|
27
|
if($show_end_time){ |
137
|
0
|
|
|
|
|
0
|
push @$time_array , |
138
|
|
|
|
|
|
|
$start_posix_time |
139
|
|
|
|
|
|
|
. "\t" |
140
|
|
|
|
|
|
|
. ($start_posix_time + $unit_time_value - 1); |
141
|
|
|
|
|
|
|
}else{ |
142
|
24
|
|
|
|
|
27
|
push @$time_array , $start_posix_time; |
143
|
|
|
|
|
|
|
} |
144
|
24
|
|
|
|
|
35
|
$start_posix_time += $unit_time_value; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
24
|
|
|
|
|
79
|
my $end_time_separate_chars = $self->end_time_separate_chars; |
150
|
24
|
100
|
|
|
|
135
|
if($output_type == ARRAY){ |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
151
|
14
|
100
|
|
|
|
25
|
if($show_end_time){ |
152
|
37
|
|
|
|
|
1941
|
return [map{ |
153
|
6
|
|
|
|
|
14
|
my ($t1 , $t2) = split("\t" , $_); |
154
|
37
|
|
|
|
|
89
|
localtime($t1)->strftime($output_strftime_form) |
155
|
|
|
|
|
|
|
. $end_time_separate_chars |
156
|
|
|
|
|
|
|
. localtime($t2)->strftime($output_strftime_form) |
157
|
|
|
|
|
|
|
}@$time_array]; |
158
|
|
|
|
|
|
|
}else{ |
159
|
8
|
|
|
|
|
13
|
return [map{localtime($_)->strftime($output_strftime_form)}@$time_array]; |
|
83
|
|
|
|
|
2315
|
|
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
}elsif($output_type == HASH){ |
162
|
6
|
100
|
|
|
|
12
|
if($show_end_time){ |
163
|
|
|
|
|
|
|
return { |
164
|
20
|
|
|
|
|
1012
|
map{ |
165
|
2
|
|
|
|
|
6
|
my ($t1 , $t2) = split("\t" , $_); |
166
|
20
|
|
|
|
|
46
|
localtime($t1)->strftime($output_strftime_form) |
167
|
|
|
|
|
|
|
. $end_time_separate_chars |
168
|
|
|
|
|
|
|
. localtime($t2)->strftime($output_strftime_form) => {} |
169
|
|
|
|
|
|
|
}@$time_array}; |
170
|
|
|
|
|
|
|
}else{ |
171
|
4
|
|
|
|
|
6
|
return {map{localtime($_)->strftime($output_strftime_form) => {}}@$time_array}; |
|
68
|
|
|
|
|
2046
|
|
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
}elsif($output_type == ROWS){ |
174
|
4
|
|
|
|
|
29
|
my %args = %$self; |
175
|
4
|
|
|
|
|
32
|
Time::List::Rows->new(%args , time_array => $time_array); |
176
|
|
|
|
|
|
|
}else{ |
177
|
0
|
|
|
|
|
|
die 'set output type'; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
1; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |
185
|
|
|
|
|
|
|
__END__ |