line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DateTime::Format::GeekTime; |
2
|
3
|
|
|
3
|
|
761745
|
use 5.005; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
128
|
|
3
|
3
|
|
|
3
|
|
21
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
106
|
|
4
|
3
|
|
|
3
|
|
19
|
use warnings; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
104
|
|
5
|
3
|
|
|
3
|
|
17
|
use DateTime; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
57
|
|
6
|
3
|
|
|
3
|
|
14
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
263
|
|
7
|
3
|
|
|
3
|
|
15
|
use vars '$VERSION'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
1958
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$VERSION='1.000_001'; |
10
|
|
|
|
|
|
|
$VERSION=eval $VERSION; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
1
|
0
|
my ($class,$year)=@_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
0
|
|
|
|
0
|
if (!defined $year) { |
16
|
0
|
|
|
|
|
0
|
$year = DateTime->now->year; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
0
|
return bless {year=>$year},$class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub parse_datetime { |
23
|
11
|
|
|
11
|
1
|
10658
|
my ($self,$string)=@_; |
24
|
|
|
|
|
|
|
|
25
|
11
|
|
|
|
|
102
|
my ($seconds,$days) = |
26
|
|
|
|
|
|
|
($string =~ m{\A \s* |
27
|
|
|
|
|
|
|
(?:0x)? ( [0-9a-fA-F]{4} ) |
28
|
|
|
|
|
|
|
(?: [\w\s]*? ) |
29
|
|
|
|
|
|
|
(?:0x)? ( [0-9a-fA-F]{3,4} ) |
30
|
|
|
|
|
|
|
(?: \s+ .)? # optional character representation |
31
|
|
|
|
|
|
|
\s* \z}smx); |
32
|
11
|
50
|
33
|
|
|
78
|
if (!(defined $seconds and defined $days)) { |
33
|
0
|
|
|
|
|
0
|
croak "<$string> is not a proper GeekTime string"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
11
|
|
|
|
|
20
|
$seconds=hex($seconds);$days=hex($days); |
|
11
|
|
|
|
|
18
|
|
37
|
|
|
|
|
|
|
|
38
|
11
|
|
|
|
|
38
|
$seconds=int($seconds*86_400/65_536+0.5); |
39
|
|
|
|
|
|
|
|
40
|
11
|
|
|
|
|
17
|
my $base_year; |
41
|
11
|
50
|
|
|
|
24
|
if (ref($self)) { |
42
|
0
|
|
|
|
|
0
|
$base_year=$self->{year}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
11
|
|
|
|
|
45
|
$base_year=DateTime->now->year; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
11
|
|
|
|
|
2852
|
my $dt=DateTime->new(year=>$base_year,time_zone=>'UTC'); |
49
|
11
|
|
|
|
|
2203
|
$dt->add(days=>$days,seconds=>$seconds); |
50
|
|
|
|
|
|
|
|
51
|
11
|
|
|
|
|
6944
|
return $dt; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub format_datetime { |
55
|
2
|
|
|
2
|
1
|
21901
|
my ($self,$dt)=@_; |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
11
|
my $start_of_day=$dt->clone->set_time_zone('UTC')->truncate(to=>'day'); |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
842
|
my $seconds=$dt->subtract_datetime_absolute($start_of_day)->in_units('seconds'); |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
317
|
my $days=$dt->day_of_year - 1; |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
|
|
|
17
|
$seconds=int($seconds/86_400*65_536+0.5); |
64
|
|
|
|
|
|
|
|
65
|
2
|
|
|
|
|
3
|
my ($chr,$warn); |
66
|
|
|
|
|
|
|
{ |
67
|
2
|
|
|
0
|
|
4
|
local $SIG{__WARN__}=sub {$warn=shift}; |
|
2
|
|
|
|
|
19
|
|
|
0
|
|
|
|
|
0
|
|
68
|
2
|
|
|
|
|
17
|
$chr=chr($seconds); |
69
|
|
|
|
|
|
|
} |
70
|
2
|
50
|
|
|
|
9
|
if (defined $warn) {$chr=''} |
|
0
|
|
|
|
|
0
|
|
|
2
|
|
|
|
|
8
|
|
71
|
|
|
|
|
|
|
else {$chr=" $chr"}; |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
35
|
return sprintf '0x%04X on day 0x%03X%s',$seconds,$days,$chr; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
__END__ |