| 1 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | package Time::D; | ||||||||||||||||||||||||||||||||
| 4 | 8 | $Time::D::VERSION = '0.024'; | |||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Differentiate between two times. | ||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use overload ( | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
| |||||||||||||||||||||||||||||||||
| 8 | 0 | ▶ | '""' => sub { shift->to_string(2); }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 9 | 0 | ▶ | bool => sub { 1 }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 10 | 9 | fallback => 1, | |||||||||||||||||||||||||||||||
| 11 | 9 | ); | |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use Carp qw/ croak /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use Function::Parameters qw/ :strict /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | use Time::C; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | use Time::C::Sentinel; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | method new ($c: $base, $comp = $base) { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 21 | 0 | bless { base => $base, comp => $comp }, $c; | |||||||||||||||||||||||||||||||
| 22 | 8 | } | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | method _setter ($d: $key, $new) { | ||||||||||||||||||||||||||||||
|
Subroutine
_setter: not called CC=3 SCAR=24.8
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 26 | 0 | $d->{$key} = $_[0]; | |||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | return $d if defined $new; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 28 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||
| 29 | 0 | }; | |||||||||||||||||||||||||||||||
| 30 | 8 | } | |||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | method _computed_setter ($d: $key, $new) { | ||||||||||||||||||||||||||||||
|
Subroutine
_computed_setter: not called CC=3 SCAR=24.8
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 33 | 0 | my %diff; | |||||||||||||||||||||||||||||||
| 34 | 0 | @diff{qw/ sign year month week day hour minute second /} = $d->to_array(); | |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 0 | my $val = $diff{$key}; | |||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 0 | my $ct = Time::C->gmtime($d->comp); | |||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | return $val, sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ($diff{sign} eq '-') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 0 | $ct->$key -= $_[0] - $val; | |||||||||||||||||||||||||||||||
| 42 | } else { | ||||||||||||||||||||||||||||||||
| 43 | 0 | $ct->$key -= $val - $_[0]; | |||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | 0 | $d->comp = $ct->epoch; | |||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | return $d if defined $new; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 48 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||
| 49 | 0 | }; | |||||||||||||||||||||||||||||||
| 50 | 8 | } | |||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | method base ($d: $new_base = undef) :lvalue { | ||||||||||||||||||||||||||||||
|
Subroutine
base: not called CC=4 SCAR=30.0
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 55 | 0 | my $setter = $d->_setter('base', $new_base); | |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | return $setter->($new_base) if defined $new_base; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 0 | sentinel value => $d->{base}, set => $setter; | |||||||||||||||||||||||||||||||
| 60 | 8 | } | |||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | method comp ($d: $new_comp = undef) :lvalue { | ||||||||||||||||||||||||||||||
|
Subroutine
comp: not called CC=4 SCAR=30.0
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 64 | 0 | my $setter = $d->_setter('comp', $new_comp); | |||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | return $setter->($new_comp) if defined $new_comp; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 0 | sentinel value => $d->{comp}, set => $setter; | |||||||||||||||||||||||||||||||
| 69 | 8 | } | |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | method sign ($d: $new_sign = undef) :lvalue { | ||||||||||||||||||||||||||||||
|
Subroutine
sign: not called CC=4 SCAR=30.0
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 73 | 0 | my %diff; | |||||||||||||||||||||||||||||||
| 74 | 0 | @diff{qw/ sign year month week day hour minute second /} = $d->to_array(); | |||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 0 | my $sign = $diff{sign}; | |||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 0 | my $ct = Time::C->gmtime($d->comp); | |||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my $setter = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ($_[0] ne '+' and $_[0] ne '-') { croak "Can't set a sign other than '+' or '-'."; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_[0] ne "+" and $_[0] ne "-"
MC/DC0%0/2
$_[0] ne "+" and $_[0] ne "-"
$_[0] ne "+"
$_[0] ne "-"
Truth table0%0/3
A and B
A= $_[0] ne "+"B= $_[0] ne "-"
| |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($_[0] ne $sign) { $d->comp += 2*($d->base-$d->comp); } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | return $d if defined $new_sign; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 86 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||
| 87 | 0 | }; | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return $setter->($new_sign) if defined $new_sign; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 0 | sentinel value => $sign, set => $setter; | |||||||||||||||||||||||||||||||
| 92 | 8 | } | |||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | method years ($d: $new_years = undef) :lvalue { | ||||||||||||||||||||||||||||||
|
Subroutine
years: not called CC=4 SCAR=30.0
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 96 | 0 | my ($years, $setter) = $d->_computed_setter('year', $new_years); | |||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | return $setter->($new_years) if defined $new_years; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 0 | sentinel value => $years, set => $setter; | |||||||||||||||||||||||||||||||
| 101 | 8 | } | |||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | method months ($d: $new_months = undef) :lvalue { | ||||||||||||||||||||||||||||||
|
Subroutine
months: not called CC=4 SCAR=30.0
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 105 | 0 | my ($months, $setter) = $d->_computed_setter('month', $new_months); | |||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | return $setter->($new_months) if defined $new_months; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | 0 | sentinel value => $months, set => $setter; | |||||||||||||||||||||||||||||||
| 110 | 8 | } | |||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | method weeks ($d: $new_weeks = undef) :lvalue { | ||||||||||||||||||||||||||||||
|
Subroutine
weeks: not called CC=4 SCAR=30.0
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 114 | 0 | my ($weeks, $setter) = $d->_computed_setter('week', $new_weeks); | |||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | return $setter->($new_weeks) if defined $new_weeks; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | 0 | sentinel value => $weeks, set => $setter; | |||||||||||||||||||||||||||||||
| 119 | 8 | } | |||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | method days ($d: $new_days = undef) :lvalue { | ||||||||||||||||||||||||||||||
|
Subroutine
days: not called CC=4 SCAR=30.0
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 123 | 0 | my ($days, $setter) = $d->_computed_setter('day', $new_days); | |||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | return $setter->($new_days) if defined $new_days; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 0 | sentinel value => $days, set => $setter; | |||||||||||||||||||||||||||||||
| 128 | 8 | } | |||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | method hours ($d: $new_hours = undef) :lvalue { | ||||||||||||||||||||||||||||||
|
Subroutine
hours: not called CC=4 SCAR=30.0
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 132 | 0 | my ($hours, $setter) = $d->_computed_setter('hour', $new_hours); | |||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | return $setter->($new_hours) if defined $new_hours; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | 0 | sentinel value => $hours, set => $setter; | |||||||||||||||||||||||||||||||
| 137 | 8 | } | |||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | method minutes ($d: $new_minutes = undef) :lvalue { | ||||||||||||||||||||||||||||||
|
Subroutine
minutes: not called CC=4 SCAR=30.0
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 141 | 0 | my ($minutes, $setter) = $d->_computed_setter('minute', $new_minutes); | |||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | return $setter->($new_minutes) if defined $new_minutes; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | 0 | sentinel value => $minutes, set => $setter; | |||||||||||||||||||||||||||||||
| 146 | 8 | } | |||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | method seconds ($d: $new_seconds = undef) :lvalue { | ||||||||||||||||||||||||||||||
|
Subroutine
seconds: not called CC=4 SCAR=30.0
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 150 | 0 | my ($seconds, $setter) = $d->_computed_setter('second', $new_seconds); | |||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | return $setter->($new_seconds) if defined $new_seconds; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | 0 | sentinel value => $seconds, set => $setter; | |||||||||||||||||||||||||||||||
| 155 | 8 | } | |||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | method to_array ($d:) { | ||||||||||||||||||||||||||||||
|
Subroutine
to_array: not called CC=29 SCAR=67.7
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 160 | 0 | my $bt = Time::C->gmtime($d->base); | |||||||||||||||||||||||||||||||
| 161 | 0 | my $ct = Time::C->gmtime($d->comp); | |||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | my $sign = $d->base > $d->comp ? '-' : '+'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | 0 | my $years = $bt->tm->delta_years($ct->tm); | |||||||||||||||||||||||||||||||
| 166 | 0 | $ct->year -= $years; | |||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | if ($sign eq '+' and $bt->epoch > $ct->epoch) { $years--; $ct->year++; } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$sign eq "+" and $bt->epoch > $ct->epoch
MC/DC0%0/2
$sign eq "+" and $bt->epoch > $ct->epoch
$sign eq "+"
$bt->epoch > $ct->epoch
Truth table0%0/3
A and B
A= $sign eq "+"B= $bt->epoch > $ct->epoch
| |||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | elsif ($sign eq '-' and $bt->epoch < $ct->epoch) { $years++; $ct->year--; } | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$sign eq "-" and $bt->epoch < $ct->epoch
MC/DC0%0/2
$sign eq "-" and $bt->epoch < $ct->epoch
$sign eq "-"
$bt->epoch < $ct->epoch
Truth table0%0/3
A and B
A= $sign eq "-"B= $bt->epoch < $ct->epoch
| |||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | 0 | my $months = $bt->tm->delta_months($ct->tm); | |||||||||||||||||||||||||||||||
| 171 | 0 | $ct->month -= $months; | |||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ($sign eq '+' and $bt->epoch > $ct->epoch) { $months--; $ct->month++; } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$sign eq "+" and $bt->epoch > $ct->epoch
MC/DC0%0/2
$sign eq "+" and $bt->epoch > $ct->epoch
$sign eq "+"
$bt->epoch > $ct->epoch
Truth table0%0/3
A and B
A= $sign eq "+"B= $bt->epoch > $ct->epoch
| |||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | elsif ($sign eq '-' and $bt->epoch < $ct->epoch) { $months++; $ct->month--; } | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$sign eq "-" and $bt->epoch < $ct->epoch
MC/DC0%0/2
$sign eq "-" and $bt->epoch < $ct->epoch
$sign eq "-"
$bt->epoch < $ct->epoch
Truth table0%0/3
A and B
A= $sign eq "-"B= $bt->epoch < $ct->epoch
| |||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | 0 | my $weeks = $bt->tm->delta_weeks($ct->tm); | |||||||||||||||||||||||||||||||
| 176 | 0 | $ct->week -= $weeks; | |||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if ($sign eq '+' and $bt->epoch > $ct->epoch) { $weeks--; $ct->week++; } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$sign eq "+" and $bt->epoch > $ct->epoch
MC/DC0%0/2
$sign eq "+" and $bt->epoch > $ct->epoch
$sign eq "+"
$bt->epoch > $ct->epoch
Truth table0%0/3
A and B
A= $sign eq "+"B= $bt->epoch > $ct->epoch
| |||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | elsif ($sign eq '-' and $bt->epoch < $ct->epoch) { $weeks++; $ct->week--; } | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$sign eq "-" and $bt->epoch < $ct->epoch
MC/DC0%0/2
$sign eq "-" and $bt->epoch < $ct->epoch
$sign eq "-"
$bt->epoch < $ct->epoch
Truth table0%0/3
A and B
A= $sign eq "-"B= $bt->epoch < $ct->epoch
| |||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | 0 | my $days = $bt->tm->delta_days($ct->tm); | |||||||||||||||||||||||||||||||
| 181 | 0 | $ct->day -= $days; | |||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if ($sign eq '+' and $bt->epoch > $ct->epoch) { $days--; $ct->day++; } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$sign eq "+" and $bt->epoch > $ct->epoch
MC/DC0%0/2
$sign eq "+" and $bt->epoch > $ct->epoch
$sign eq "+"
$bt->epoch > $ct->epoch
Truth table0%0/3
A and B
A= $sign eq "+"B= $bt->epoch > $ct->epoch
| |||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | elsif ($sign eq '-' and $bt->epoch < $ct->epoch) { $days++; $ct->day--; } | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$sign eq "-" and $bt->epoch < $ct->epoch
MC/DC0%0/2
$sign eq "-" and $bt->epoch < $ct->epoch
$sign eq "-"
$bt->epoch < $ct->epoch
Truth table0%0/3
A and B
A= $sign eq "-"B= $bt->epoch < $ct->epoch
| |||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | 0 | my $hours = $bt->tm->delta_hours($ct->tm); | |||||||||||||||||||||||||||||||
| 186 | 0 | $ct->hour -= $hours; | |||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if ($sign eq '+' and $bt->epoch > $ct->epoch) { $hours--; $ct->hour++; } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$sign eq "+" and $bt->epoch > $ct->epoch
MC/DC0%0/2
$sign eq "+" and $bt->epoch > $ct->epoch
$sign eq "+"
$bt->epoch > $ct->epoch
Truth table0%0/3
A and B
A= $sign eq "+"B= $bt->epoch > $ct->epoch
| |||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | elsif ($sign eq '-' and $bt->epoch < $ct->epoch) { $hours++; $ct->hour--; } | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$sign eq "-" and $bt->epoch < $ct->epoch
MC/DC0%0/2
$sign eq "-" and $bt->epoch < $ct->epoch
$sign eq "-"
$bt->epoch < $ct->epoch
Truth table0%0/3
A and B
A= $sign eq "-"B= $bt->epoch < $ct->epoch
| |||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||
| 190 | 0 | my $minutes = $bt->tm->delta_minutes($ct->tm); | |||||||||||||||||||||||||||||||
| 191 | 0 | $ct->minute -= $minutes; | |||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if ($sign eq '+' and $bt->epoch > $ct->epoch) { $minutes--; $ct->minute++; } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$sign eq "+" and $bt->epoch > $ct->epoch
MC/DC0%0/2
$sign eq "+" and $bt->epoch > $ct->epoch
$sign eq "+"
$bt->epoch > $ct->epoch
Truth table0%0/3
A and B
A= $sign eq "+"B= $bt->epoch > $ct->epoch
| |||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | elsif ($sign eq '-' and $bt->epoch < $ct->epoch) { $minutes++; $ct->minute--; } | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$sign eq "-" and $bt->epoch < $ct->epoch
MC/DC0%0/2
$sign eq "-" and $bt->epoch < $ct->epoch
$sign eq "-"
$bt->epoch < $ct->epoch
Truth table0%0/3
A and B
A= $sign eq "-"B= $bt->epoch < $ct->epoch
| |||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | 0 | my $seconds = $bt->tm->delta_seconds($ct->tm); | |||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | if ($sign eq '-') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 198 | 0 | ($years, $months, $weeks, $days, $hours, $minutes, $seconds) = | |||||||||||||||||||||||||||||||
| 199 | (-$years, -$months, -$weeks, -$days, -$hours, -$minutes, -$seconds); | ||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||
| 202 | 0 | return $sign, $years, $months, $weeks, $days, $hours, $minutes, $seconds; | |||||||||||||||||||||||||||||||
| 203 | 8 | } | |||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | fun _plural ($num, $sing, $plur) { sprintf "%s %s", $num, $num == 1 ? $sing : $plur; } | ||||||||||||||||||||||||||||||
|
Subroutine
_plural: not called CC=4 SCAR=27.9
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | method to_string ($d: $precision = 7) { | ||||||||||||||||||||||||||||||
|
Subroutine
to_string: not called CC=21 SCAR=61.4
Pod
documented
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 209 | 0 | my ($sign, $years, $months, $weeks, $days, $hours, $minutes, $seconds) = | |||||||||||||||||||||||||||||||
| 210 | $d->to_array(); | ||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||
| 212 | 0 | my @out; | |||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if ($precision > 0 and $years) { $precision--; push @out, _plural($years, 'year', 'years'); } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$precision > 0 and $years
MC/DC0%0/2
$precision > 0 and $years
$precision > 0
$years
Truth table0%0/3
A and B
A= $precision > 0B= $years
| |||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ($precision > 0 and $months) { $precision--; push @out, _plural($months, 'month', 'months'); } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$precision > 0 and $months
MC/DC0%0/2
$precision > 0 and $months
$precision > 0
$months
Truth table0%0/3
A and B
A= $precision > 0B= $months
| |||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if ($precision > 0 and $weeks) { $precision--; push @out, _plural($weeks, 'week', 'weeks'); } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$precision > 0 and $weeks
MC/DC0%0/2
$precision > 0 and $weeks
$precision > 0
$weeks
Truth table0%0/3
A and B
A= $precision > 0B= $weeks
| |||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if ($precision > 0 and $days) { $precision--; push @out, _plural($days, 'day', 'days'); } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$precision > 0 and $days
MC/DC0%0/2
$precision > 0 and $days
$precision > 0
$days
Truth table0%0/3
A and B
A= $precision > 0B= $days
| |||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if ($precision > 0 and $hours) { $precision--; push @out, _plural($hours, 'hour', 'hours'); } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$precision > 0 and $hours
MC/DC0%0/2
$precision > 0 and $hours
$precision > 0
$hours
Truth table0%0/3
A and B
A= $precision > 0B= $hours
| |||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if ($precision > 0 and $minutes) { $precision--; push @out, _plural($minutes, 'minute', 'minutes'); } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$precision > 0 and $minutes
MC/DC0%0/2
$precision > 0 and $minutes
$precision > 0
$minutes
Truth table0%0/3
A and B
A= $precision > 0B= $minutes
| |||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if ($precision > 0 and $seconds) { $precision--; push @out, _plural($seconds, 'second', 'seconds'); } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$precision > 0 and $seconds
MC/DC0%0/2
$precision > 0 and $seconds
$precision > 0
$seconds
Truth table0%0/3
A and B
A= $precision > 0B= $seconds
| |||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | return "now" unless @out; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if (@out > 1) { $out[-1] = "and $out[-1]"; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | 0 | my $pretty = join ", ", @out; | |||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | return sprintf $sign eq '+' ? "in %s" : "%s ago", $pretty; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 229 | 8 | } | |||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||
| 231 | 8 | 1; | |||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | __END__ | ||||||||||||||||||||||||||||||||