line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DateTime::Format::Epoch::TAI64;
|
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
213146
|
use strict;
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
98
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
11
|
use vars qw($VERSION @ISA);
|
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
158
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$VERSION = '0.13';
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1063
|
use DateTime;
|
|
3
|
|
|
|
|
100492
|
|
|
3
|
|
|
|
|
49
|
|
10
|
3
|
|
|
3
|
|
904
|
use DateTime::Format::Epoch;
|
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
76
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
13
|
use Params::Validate qw/validate/;
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
117
|
|
13
|
3
|
50
|
|
3
|
|
10
|
use Math::BigInt ('lib' => $^O eq 'MSWin32' ? 'Pari,FastCalc' : 'GMP,Pari,FastCalc');
|
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
19
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
@ISA = qw/DateTime::Format::Epoch/;
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Epoch is 1970-01-01 00:00:00 TAI, is 1969-12-31T23:59:50 'utc'
|
18
|
|
|
|
|
|
|
my $epoch = DateTime->new( year => 1969, month => 12, day => 31,
|
19
|
|
|
|
|
|
|
hour => 23, minute => 59, second => 50 );
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $start = Math::BigInt->new(1) << 62;
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new {
|
24
|
2
|
|
|
2
|
1
|
20
|
my $class = shift;
|
25
|
2
|
|
|
|
|
44
|
my %p = validate( @_,
|
26
|
|
|
|
|
|
|
{ format => { regex => qr/^string|number$/,
|
27
|
|
|
|
|
|
|
default => 'number' },
|
28
|
|
|
|
|
|
|
});
|
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
43
|
my $self = $class->SUPER::new( epoch => $epoch,
|
31
|
|
|
|
|
|
|
unit => 'seconds',
|
32
|
|
|
|
|
|
|
type => 'bigint',
|
33
|
|
|
|
|
|
|
skip_leap_seconds => 0,
|
34
|
|
|
|
|
|
|
start_at => $start );
|
35
|
2
|
|
|
|
|
10
|
$self->{is_string} = ($p{format} eq 'string');
|
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
5
|
return $self;
|
38
|
|
|
|
|
|
|
}
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub format_datetime {
|
41
|
1
|
|
|
1
|
1
|
526
|
my ($self, $dt) = @_;
|
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
5
|
my $n = $self->SUPER::format_datetime($dt);
|
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
|
|
|
3
|
if ($self->{is_string}) {
|
46
|
1
|
|
|
|
|
3
|
my $str = $n->as_hex;
|
47
|
1
|
50
|
|
|
|
119
|
my ($hex) = $str =~ /^0x(\w+)$/
|
48
|
|
|
|
|
|
|
or die "Unknown BigInt format '$str'\n";
|
49
|
1
|
|
|
|
|
3
|
my $retval = pack "H*", $hex;
|
50
|
1
|
|
|
|
|
3
|
$n = "0" x (8 - length$retval) . $retval;
|
51
|
|
|
|
|
|
|
}
|
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
5
|
return $n;
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub parse_datetime {
|
57
|
1
|
|
|
1
|
1
|
330
|
my ($self, $n) = @_;
|
58
|
|
|
|
|
|
|
|
59
|
1
|
50
|
|
|
|
3
|
if ($self->{is_string}) {
|
60
|
1
|
|
|
|
|
5
|
my $hexstr = '0x' . unpack 'H*', $n;
|
61
|
1
|
|
|
|
|
5
|
$n = Math::BigInt->new($hexstr);
|
62
|
|
|
|
|
|
|
}
|
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
175
|
return $self->SUPER::parse_datetime($n);
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1;
|
68
|
|
|
|
|
|
|
__END__
|