blib/lib/DateTime/PPExtra.pm

filter: Statementstmt 65.9% 31 / 47 Branchbran 30.0% 3 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 87.5% 7 / 8 Podpod n/a totaltotal 65.7% 46 / 70 CC 7 SCAR 17.5
CC
7
Cov
62%
_normalize_leap_seconds
14.7
_normalize_tai_seconds
4.0
BEGIN
1.0
CRAP 5.8
« blib/lib/DateTime/PP.pm ↑ Summary blib/lib/DateTime.pm »
1 package DateTime::PPExtra;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.68';
7  
8 1 ▶use DateTime::LeapSecond;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
11 3 ▶sub _normalize_tai_seconds {
Subroutine _normalize_tai_seconds: called CC=4 SCAR=13.9
12 return
13 if
14 3 ▶ grep { $_ == DateTime::INFINITY() || $_ == DateTime::NEG_INFINITY() }
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ == "Inf" or $_ == "-Inf";} @_[1, 2] 2 1 3
Condition100%3/3
$_ == 9**9**9 || $_ == -9**9**9
l!l&&r!l&&!r
222
MC/DC100%2/2
$_ == 9**9**9 || $_ == -9**9**9
$_ == 9**9**9 $_ == -9**9**9
Truth table100%3/3
A || B
A= $_ == 9**9**9B= $_ == -9**9**9
ABresult
1X1
011
000
15 @_[ 1, 2 ];
16  
17 # This must be after checking for infinity, because it breaks in
18 # presence of use integer !
19 1 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 my $adj;
22  
23 1 ▶ if ( $_[2] < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2] < 0) { } 0 1 1
24 0 $adj = ( $_[2] - 86399 ) / 86400;
25 }
26 else {
27 1 $adj = $_[2] / 86400;
28 }
29  
30 1 $_[1] += $adj;
31  
32 1 $_[2] -= $adj * 86400;
33 }
34  
35 0 ▶sub _normalize_leap_seconds {
Subroutine _normalize_leap_seconds: not called CC=4 SCAR=26.9
36  
37 # args: 0 => days, 1 => seconds
38 0 my $delta_days;
39  
40 1 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 # rough adjust - can adjust many days
43 0 ▶ if ( $_[2] < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2] < 0) { } 0 0 0
44 0 $delta_days = ( $_[2] - 86399 ) / 86400;
45 }
46 else {
47 0 $delta_days = $_[2] / 86400;
48 }
49  
50 0 my $new_day = $_[1] + $delta_days;
51 0 my $delta_seconds
52 = ( 86400 * $delta_days )
53 + DateTime::LeapSecond::leap_seconds($new_day)
54 - DateTime::LeapSecond::leap_seconds( $_[1] );
55  
56 0 $_[2] -= $delta_seconds;
57 0 $_[1] = $new_day;
58  
59 # fine adjust - up to 1 day
60 0 my $day_length = DateTime::LeapSecond::day_length($new_day);
61 0 ▶ if ( $_[2] >= $day_length ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_[2] >= $day_length) { } 0 0 0
elsif ($_[2] < 0) { } 0 0 0
62 0 $_[2] -= $day_length;
63 0 $_[1]++;
64 }
65 elsif ( $_[2] < 0 ) {
66 0 $day_length = DateTime::LeapSecond::day_length( $new_day - 1 );
67 0 $_[2] += $day_length;
68 0 $_[1]--;
69 }
70 }
71  
72 1 my @subs = qw(
73 _normalize_tai_seconds
74 _normalize_leap_seconds
75 );
76  
77 1 for my $sub (@subs) {
78 ## no critic (TestingAndDebugging::ProhibitNoStrict)
79 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
80 2 *{ 'DateTime::' . $sub } = __PACKAGE__->can($sub);
81 }
82  
83 1 1;
« blib/lib/DateTime/PP.pm ↑ Summary blib/lib/DateTime.pm »