blib/lib/DateTime/Format/GeekTime.pm

filter: Statementstmt 95.5% 43 / 45 Branchbran 75.0% 6 / 8 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 86.6% 65 / 75 CC 7 SCAR 8.7
CC
7
Cov
88%
parse_datetime
4.1
format_datetime
3.0
new
2.1
CRAP 2.4
↑ Summary
1 package DateTime::Format::GeekTime;
2 3 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 $VERSION='1.001';
10 3 $VERSION=eval $VERSION;
11  
12 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.6
Pod documented
13 1 my ($class,$year)=@_;
14  
15 1 ▶ if (!defined $year) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $year) 0 1 1
16 0 $year = DateTime->now->year;
17 }
18  
19 1 return bless {year=>$year},$class;
20 }
21  
22 11 ▶sub parse_datetime {
Subroutine parse_datetime: called CC=4 SCAR=14.1
Pod documented
23 11 my ($self,$string)=@_;
24  
25 11 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 ▶ if (!(defined $seconds and defined $days)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $seconds and defined $days) 0 11 11
Condition33%1/3
defined $seconds and defined $days
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $seconds and defined $days
defined $seconds defined $days
Truth table33%1/3
A and B
A= defined $secondsB= defined $days
ABresult
0X0
100
111
33 0 croak "<$string> is not a proper GeekTime string";
34 }
35  
36 11 $seconds=hex($seconds);$days=hex($days);
37  
38 11 $seconds=int($seconds*86_400/65_536+0.5);
39  
40 11 my $base_year;
41 11 ▶ if (ref($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 10 1 11
42 10 $base_year=$self->{year};
43 }
44 else {
45 1 $base_year=DateTime->now->year;
46 }
47  
48 11 my $dt=DateTime->new(year=>$base_year,time_zone=>'UTC');
49 11 $dt->add(days=>$days,seconds=>$seconds);
50  
51 11 return $dt;
52 }
53  
54 2 ▶sub format_datetime {
Subroutine format_datetime: called CC=3 SCAR=11.0
Pod documented
55 2 my ($self,$dt)=@_;
56  
57 2 my $start_of_day=$dt->clone->set_time_zone('UTC')->truncate(to=>'day');
58  
59 2 my $seconds=$dt->subtract_datetime_absolute($start_of_day)->in_units('seconds');
60  
61 2 my $days=$dt->day_of_year - 1;
62  
63 2 $seconds=int($seconds/86_400*65_536+0.5);
64  
65 2 ▶ my $chr = $seconds <= 0xD800 || $seconds >= 0xDFFF
Branch: 1 branch
BranchTrueFalseTotal
$seconds <= 55296 || $seconds >= 57343 ? : 1 1 2
Condition66%2/3
$seconds <= 55296 or $seconds >= 57343
l!l&&r!l&&!r
101
MC/DC50%1/2
$seconds <= 55296 or $seconds >= 57343
$seconds <= 55296 $seconds >= 57343
Truth table66%2/3
A or B
A= $seconds <= 55296B= $seconds >= 57343
ABresult
1X1
011
000
66 ? ' '.chr($seconds)
67 : '';
68  
69 2 return sprintf '0x%04X on day 0x%03X%s',$seconds,$days,$chr;
70 }
71  
72 3 1;
73 __END__
↑ Summary