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