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