line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Druid::Util; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
29
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
4
|
use Exporter qw< import >; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
239
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Exporter settings |
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
9
|
|
|
|
|
|
|
iso8601_yyyy_mm_dd_hh_mm_ss |
10
|
|
|
|
|
|
|
yyyy_mm_dd_hh_mm_ss_iso8601 |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $ISO8601_RE = qr{ |
14
|
|
|
|
|
|
|
^ |
15
|
|
|
|
|
|
|
( [0-9]{4} ) # YYYY (Year) |
16
|
|
|
|
|
|
|
- |
17
|
|
|
|
|
|
|
( [0-9]{2} ) # MM (Month) |
18
|
|
|
|
|
|
|
- |
19
|
|
|
|
|
|
|
( [0-9]{2} ) T # DD (Day) |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# HH:MM:SS.mmm |
22
|
|
|
|
|
|
|
# Hour:Minute:Second.milliseconds |
23
|
|
|
|
|
|
|
( [0-9]{2} ) : ( [0-9]{2} ) : ([0-9]{2} ) . ( [0-9]{3} ) Z |
24
|
|
|
|
|
|
|
$ |
25
|
|
|
|
|
|
|
}xms; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $YYYYMMDD_RE = qr{ |
28
|
|
|
|
|
|
|
^ |
29
|
|
|
|
|
|
|
( [0-9]{4} ) # YY |
30
|
|
|
|
|
|
|
-? |
31
|
|
|
|
|
|
|
( [0-9]{2} ) # MM |
32
|
|
|
|
|
|
|
-? |
33
|
|
|
|
|
|
|
( [0-9]{2} ) # DD |
34
|
|
|
|
|
|
|
\s* |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# HH:MM:SS or HHMMSS |
37
|
|
|
|
|
|
|
# Hour:Minute:Second or HourMinuteSecond |
38
|
|
|
|
|
|
|
( [0-9]{2} ) :? ( [0-9]{2} ) :? ( [0-9]{2} ) |
39
|
|
|
|
|
|
|
$ |
40
|
|
|
|
|
|
|
}xms; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub iso8601_yyyy_mm_dd_hh_mm_ss { |
43
|
0
|
|
|
0
|
0
|
|
my $iso_date = shift; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if ( $iso_date =~ $ISO8601_RE ) { |
46
|
0
|
|
|
|
|
|
return sprintf '%s-%02d-%02d %02d:%02d:%02d', $1, $2, $3, $4, $5, $6; |
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
|
|
|
|
|
die "'$iso_date' not a valid ISO8601 format.\n"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub yyyy_mm_dd_hh_mm_ss_iso8601 { |
54
|
0
|
|
|
0
|
0
|
|
my $yyyy_mm_dd_hh_mm_ss = shift; |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if ( $yyyy_mm_dd_hh_mm_ss =~ $YYYYMMDD_RE ) { |
57
|
0
|
|
|
|
|
|
return sprintf '%s-%02d-%02dT%02d:%02d:%02d', $1, $2, $3, $4, $5, $6; |
58
|
|
|
|
|
|
|
} else { |
59
|
0
|
|
|
|
|
|
die "'$yyyy_mm_dd_hh_mm_ss' not a valid YYYYMMDDHHMMSS or YYYY-MM-DD HH:MM:SS format.\n"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |