line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bootylicious::Timestamp; |
2
|
|
|
|
|
|
|
|
3
|
19
|
|
|
19
|
|
42652
|
use strict; |
|
19
|
|
|
|
|
37
|
|
|
19
|
|
|
|
|
422
|
|
4
|
19
|
|
|
19
|
|
82
|
use warnings; |
|
19
|
|
|
|
|
36
|
|
|
19
|
|
|
|
|
410
|
|
5
|
|
|
|
|
|
|
|
6
|
19
|
|
|
19
|
|
81
|
use base 'Mojo::Base'; |
|
19
|
|
|
|
|
43
|
|
|
19
|
|
|
|
|
7440
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Time::Local; |
9
|
|
|
|
|
|
|
require Time::Piece; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->attr('epoch'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $TIMESTAMP_RE = qr/(\d\d\d\d)(\d?\d)(\d?\d)(?:T(\d\d):?(\d\d):?(\d\d))?/; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
287
|
|
|
287
|
1
|
10683
|
my $self = shift->SUPER::new; |
17
|
287
|
|
|
|
|
1920
|
my %params = @_; |
18
|
|
|
|
|
|
|
|
19
|
287
|
100
|
|
|
|
682
|
if (exists $params{epoch}) { |
20
|
206
|
|
|
|
|
509
|
$self->epoch($params{epoch}); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
else { |
23
|
81
|
|
|
|
|
227
|
my $epoch = $self->_to_epoch($params{timestamp}); |
24
|
81
|
|
|
|
|
257
|
$self->epoch($epoch); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
287
|
|
|
|
|
2277
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _to_epoch { |
31
|
81
|
|
|
81
|
|
130
|
my $self = shift; |
32
|
81
|
|
|
|
|
126
|
my $timestamp = shift; |
33
|
|
|
|
|
|
|
|
34
|
81
|
50
|
|
|
|
1039
|
return unless $timestamp =~ qr/^$TIMESTAMP_RE$/; |
35
|
|
|
|
|
|
|
|
36
|
81
|
|
100
|
|
|
909
|
my ($year, $month, $day, $hour, $minute, $second) = |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
37
|
|
|
|
|
|
|
($1, $2, $3, ($4 || 0), ($5 || 0), ($6 || 0)); |
38
|
|
|
|
|
|
|
|
39
|
81
|
|
|
|
|
154
|
my $epoch = 0; |
40
|
81
|
|
|
|
|
151
|
eval { |
41
|
81
|
|
|
|
|
365
|
$epoch = |
42
|
|
|
|
|
|
|
Time::Local::timegm($second, $minute, $hour, $day, $month - 1, |
43
|
|
|
|
|
|
|
$year - 1900); |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
81
|
50
|
33
|
|
|
2907
|
return if $@ || $epoch < 0; |
47
|
|
|
|
|
|
|
|
48
|
81
|
|
|
|
|
192
|
return $epoch; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub year { |
52
|
47
|
|
|
47
|
0
|
1177
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
47
|
|
|
|
|
130
|
return Time::Piece->gmtime($self->epoch)->year; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub month { |
58
|
39
|
|
|
39
|
0
|
547
|
my $self = shift; |
59
|
|
|
|
|
|
|
|
60
|
39
|
|
|
|
|
108
|
return Time::Piece->gmtime($self->epoch)->mon; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub timestamp { |
64
|
11
|
|
|
11
|
0
|
825
|
my $self = shift; |
65
|
|
|
|
|
|
|
|
66
|
11
|
|
|
|
|
37
|
my $t = Time::Piece->gmtime($self->epoch); |
67
|
|
|
|
|
|
|
|
68
|
11
|
|
|
|
|
735
|
return $t->strftime('%Y%m%dT%H:%M:%S'); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub strftime { |
72
|
7
|
|
|
7
|
0
|
18
|
my $self = shift; |
73
|
7
|
|
|
|
|
14
|
my $fmt = shift; |
74
|
|
|
|
|
|
|
|
75
|
7
|
|
|
|
|
21
|
my $t = Time::Piece->gmtime($self->epoch); |
76
|
|
|
|
|
|
|
|
77
|
7
|
|
|
|
|
394
|
return $t->strftime($fmt); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub is_timestamp { |
81
|
2
|
|
|
2
|
0
|
435
|
my $self = shift; |
82
|
2
|
|
|
|
|
4
|
my $timestamp = shift; |
83
|
|
|
|
|
|
|
|
84
|
2
|
100
|
|
|
|
48
|
return $timestamp =~ qr/^$TIMESTAMP_RE$/ ? 1 : 0; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |