Epoch/TAI64.pm

filter: Statementstmt 100% 41 / 41 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 93.4% 57 / 61 CC 5 SCAR 5.8
CC
5
Cov
92%
format_datetime
3.0
BEGIN
2.0
parse_datetime
2.0
CRAP 1.8
« Epoch.pm ↑ Summary Epoch/ActiveDirectory.pm »
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
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 3 3
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
BranchTrueFalseTotal
if ($self->{"is_string"}) 1 0 1
46 1 my $str = $n->as_hex;
47 1 ▶ my ($hex) = $str =~ /^0x(\w+)$/
Branch: 1 branch
BranchTrueFalseTotal
my($hex) = $str =~ /^0x(\w+)$/ or die "Unknown BigInt format '${str}'\n" 1 0 1
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
BranchTrueFalseTotal
if ($self->{"is_string"}) 1 0 1
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__
« Epoch.pm ↑ Summary Epoch/ActiveDirectory.pm »