Usul/Time.pm

filter: Statementstmt 80.3% 123 / 153 Branchbran 56.3% 62 / 110 Conditioncond 39.7% 31 / 78 MC/DCmcdc 5.0% 2 / 40 Subroutinesub 88.2% 15 / 17 Podpod 100% 5 / 5 totaltotal 59.0% 238 / 403 CC 84 SCAR 58.6
CC
84
Cov
63%
str2time
486.6
str2time_piece
6.7
nap
5.5
CRAP 351.3
↑ Summary Usul/IPC.pm »
1 package Class::Usul::Time;
2  
3 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 ▶use Class::Usul::Constants qw( EXCEPTION_CLASS FALSE TRUE );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use Class::Usul::Functions qw( ensure_class_loaded throw );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 19 ▶use Date::Format ( );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use Exporter 5.57 qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use Time::HiRes qw( usleep );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 19 ▶use Time::Zone;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 19 ▶use Unexpected::Functions qw( DateTimeCoercion );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 19 our @EXPORT = qw( str2time time2str );
16 19 our @EXPORT_OK = qw( nap str2date_time str2time str2time_piece time2str );
17  
18 # Private package variables
19 19 my $_datetime_loaded = FALSE;
20 19 my $_time_piece_loaded = FALSE;
21  
22 # Public functions
23 668 ▶sub nap ($) {
Subroutine nap: called CC=4 SCAR=17.1
Pod documented
24 668 my $period = shift;
25  
26 668 ▶ $period = $period && $period =~ m{ \A [\d._]+ \z }msx && $period > 0
Branch: 1 branch
BranchTrueFalseTotal
$period && $period =~ / \A [\d._]+ \z /msx && $period > 0 ? : 668 0 668
Condition33%2/6
$period and $period =~ / \A [\d._]+ \z /msx and $period > 0
!ll&&!rl&&r
00668
$period and $period =~ / \A [\d._]+ \z /msx
!ll&&!rl&&r
00668
MC/DC0%0/3
$period and $period =~ / \A [\d._]+ \z /msx and $period > 0
$period $period =~ / \A [\d._]+ \z /msx $period > 0
Truth table25%1/4
A and B and C
A= $periodB= $period =~ / \A [\d._]+ \z /msxC= $period > 0
ABCresult
0XX0
10X0
1100
1111
27 ? $period : 1;
28  
29 668 return usleep( 1_000_000 * $period );
30 }
31  
32 5 ▶sub str2date_time ($;$) {
Subroutine str2date_time: called CC=4 SCAR=14.1
Pod documented
33 5 my ($dstr, $zone) = @_; my $time = str2time( $dstr, $zone );
34  
35 5 ▶ defined $time or throw DateTimeCoercion, [ $dstr ];
Branch: 1 branch
BranchTrueFalseTotal
defined $time or &throw(DateTimeCoercion(), [$dstr]) 3 2 5
36  
37 3 ▶ $_datetime_loaded or (ensure_class_loaded 'DateTime::Format::Epoch'
Branch: 1 branch
BranchTrueFalseTotal
$_datetime_loaded or &ensure_class_loaded("DateTime::Format::Epoch") and $_datetime_loaded = 1 1 2 3
Condition50%3/6
$_datetime_loaded || &ensure_class_loaded('DateTime::Format::Epoch') && ($_datetime_loaded = 1)
l!l
120
&ensure_class_loaded("DateTime::Format::Epoch") and $_datetime_loaded = 1
!ll
020
MC/DC0%0/3
$_datetime_loaded || &ensure_class_loaded('DateTime::Format::Epoch') && ($_datetime_loaded = 1)
$_datetime_loaded &ensure_class_loaded("DateTime::Format::Epoch") $_datetime_loaded = 1
Truth table0%0/4
A || B and C
A= $_datetime_loadedB= &ensure_class_loaded("DateTime::Format::Epoch")C= $_datetime_loaded = 1
ABCresult
1XX1
0111
00X0
0100
38 and $_datetime_loaded = TRUE);
39  
40 3 my $dt = DateTime->new( year => 1970, month => 1, day => 1, );
41 3 my $formatter = DateTime::Format::Epoch->new
42 ( epoch => $dt,
43 unit => 'seconds',
44 type => 'int',
45 skip_leap_seconds => TRUE,
46 start_at => 0,
47 local_epoch => undef, );
48  
49 3 return $formatter->parse_datetime( $time );
50 }
51  
52 11 ▶sub str2time ($;$) {
Subroutine str2time: called CC=72 SCAR=61.9
Pod documented
53 # This subroutine: Copyright (c) 1995 Graham Barr. All rights reserved.
54 # British version dd/mm/yyyy
55 11 my ($dtstr, $zone) = @_;
56  
57 11 ▶ (defined $dtstr and length $dtstr) or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $dtstr and length $dtstr or return 11 0 11
Condition33%1/3
defined $dtstr and length $dtstr
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $dtstr and length $dtstr
defined $dtstr length $dtstr
Truth table33%1/3
A and B
A= defined $dtstrB= length $dtstr
ABresult
0X0
100
111
58  
59 11 my ($year, $month, $day, $hh, $mm, $ss, $dst, $frac, $m, $h, $result);
60 11 my %day =
61 ( sunday => 0, monday => 1, tuesday => 2, tues => 2,
62 wednesday => 3, wednes => 3, thursday => 4, thur => 4,
63 thurs => 4, friday => 5, saturday => 6, );
64 11 my %month =
65 ( january => 0, february => 1, march => 2, april => 3,
66 may => 4, june => 5, july => 6, august => 7,
67 september => 8, sept => 8, october => 9, november =>10,
68 december => 11, );
69 11 my @suf = (qw( th st nd rd th th th th th th )) x 3;
70 11 @suf[11, 12, 13] = qw( th th th );
71  
72 11 $day{ substr $_, 0, 3 } = $day{ $_ } for (keys %day);
73 11 $month{ substr $_, 0, 3 } = $month{ $_ } for (keys %month);
74  
75 11 my $daypat = join '|', reverse sort keys %day;
76 11 my $monpat = join '|', reverse sort keys %month;
77 11 my $sufpat = join '|', reverse sort @suf;
78 11 my $dstpat = 'bst|dst';
79  
80 11 my %ampm = ( a => 0, p => 12 ); my ($AM, $PM) = ( 0, 12 );
81  
82 11 my $merid = 24; my @lt = localtime time;
83  
84 11 $dtstr = lc $dtstr;
85 11 ▶ $zone = tz_offset( $zone ) if ($zone);
Branch: 1 branch
BranchTrueFalseTotal
if $zone 8 3 11
86  
87 11 ▶ 1 while ($dtstr =~ s{\([^\(\)]*\)}{ }mox);
Branch: 1 branch
BranchTrueFalseTotal
$dtstr =~ s/\([^\(\)]*\)/ /mox and do { '???' } 0 11 11
88  
89 11 $dtstr =~ s{ (\A|\n|\z) }{ }gmox;
90 11 $dtstr =~ s{ ([\d\w\s]) [\.\,] \s }{$1 }gmox;
91 11 $dtstr =~ s{ , }{ }gmx;
92 11 $dtstr =~ s{ ($daypat) \s* (den\s)? }{ }mox;
93  
94 11 ▶ return unless ($dtstr =~ m{ \S }mx);
Branch: 1 branch
BranchTrueFalseTotal
unless $dtstr =~ / \S /mx 0 11 11
95  
96 11 ▶ if ($dtstr =~ s{ \s (\d{4}) ([-:]?) # ccyy + optional separator - or : (1)
Branch: 1 branch
BranchTrueFalseTotal
if ($dtstr =~ s/ \s (\d{4}) ([-:]?) # ccyy + optional separator - or : (1) (\d\d?) \2 # mm(1 - 12) + same separator (1) (\d\d?) # dd(1 - 31) (?:[Tt ] (\d\d?) # H or HH (?:([-:]?) # Optionally separator - or : (2) (\d\d?) # and M or MM (?:\6 # Optionally same separator (2) (\d\d?) # and S or SS (?:[.,] # Optionally separator . or , (\d+) )? # and fractions of a second )? )? )? (?=\D) / /mx) 3 8 11
97 (\d\d?) \2 # mm(1 - 12) + same separator (1)
98 (\d\d?) # dd(1 - 31)
99 (?:[Tt ]
100 (\d\d?) # H or HH
101 (?:([-:]?) # Optionally separator - or : (2)
102 (\d\d?) # and M or MM
103 (?:\6 # Optionally same separator (2)
104 (\d\d?) # and S or SS
105 (?:[.,] # Optionally separator . or ,
106 (\d+) )? # and fractions of a second
107 )? )? )?
108 (?=\D)
109 }{ }mx) {
110 3 ($year, $month, $day, $hh, $mm, $ss, $frac)
111 = ($1, $3-1, $4, $5, $7, $8, $9);
112 }
113  
114 11 ▶ unless (defined $hh) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hh) 8 3 11
115 8 ▶ if ($dtstr =~ s{ [:\s] (\d\d?) : (\d\d?) ( : (\d\d?) (?:\.\d+)? )? \s*
Branch: 2 branches
BranchTrueFalseTotal
if ($dtstr =~ s/ [:\s] (\d\d?) : (\d\d?) ( : (\d\d?) (?:\.\d+)? )? \s* (?:([ap]) \.?m?\.? )? \s / /mox) { } 3 5 8
elsif ($dtstr =~ s/ \s (\d\d?) \s* ([ap]) \.?m?\.? \s / /mox) { } 0 5 5
116 (?:([ap]) \.?m?\.? )? \s }{ }mox) {
117 3 ▶ ($hh, $mm, $ss) = ($1, $2, $4 || 0);
Condition100%2/2
$4 || 0
l!l
12
MC/DC100%1/1
$4 || 0
$4
Truth table100%2/2
A
A= $4
Aresult
11
00
118 3 ▶ $merid = $ampm{ $5 } if ($5);
Branch: 1 branch
BranchTrueFalseTotal
if $5 0 3 3
119 }
120 elsif ($dtstr =~ s{ \s (\d\d?) \s* ([ap]) \.?m?\.? \s }{ }mox) {
121 0 ($hh, $mm, $ss) = ($1, 0, 0);
122 0 $merid = $ampm{ $2 };
123 }
124 }
125  
126 11 ▶ if (defined $hh && $hh <= 12 && $dtstr =~ s{ ([ap]) \.?m?\.? \s }{ }mox) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hh and $hh <= 12 and $dtstr =~ s/ ([ap]) \.?m?\.? \s / /mox) 0 11 11
Condition83%5/6
defined $hh and $hh <= 12 and $dtstr =~ s/ ([ap]) \.?m?\.? \s / /mox
!ll&&!rl&&r
650
defined $hh and $hh <= 12
!ll&&!rl&&r
515
MC/DC0%0/3
defined $hh and $hh <= 12 and $dtstr =~ s/ ([ap]) \.?m?\.? \s / /mox
defined $hh $hh <= 12 $dtstr =~ s/ ([ap]) \.?m?\.? \s / /mox
Truth table75%3/4
A and B and C
A= defined $hhB= $hh <= 12C= $dtstr =~ s/ ([ap]) \.?m?\.? \s / /mox
ABCresult
0XX0
10X0
1100
1111
127 0 $merid = $ampm{ $1 };
128 }
129  
130 11 ▶ unless (defined $year) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $year) 8 3 11
131 TRY: {
132 8 ▶ if ($dtstr =~ s{ \s (\d\d?) ([^\d_]) ($monpat) (\2(\d\d+))? \s}{ }mox) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dtstr =~ s/ \s (\d\d?) ([^\d_]) ($monpat) (\2(\d\d+))? \s/ /mox) 0 8 8
133 0 ($year, $month, $day) = ($5, $month{ $3 }, $1);
134 0 last TRY;
135 }
136  
137 8 ▶ if ($dtstr =~ s{ \s (\d+) ([\-\./]) (\d\d?) (\2(\d+))? \s }{ }mox) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dtstr =~ s[ \s (\d+) ([\-\./]) (\d\d?) (\2(\d+))? \s ][ ]mox) 6 2 8
138 6 ($year, $month, $day) = ($5, $3 - 1, $1);
139 6 ▶ ($year, $day) = ($1, $5) if ($day > 31);
Branch: 1 branch
BranchTrueFalseTotal
if $day > 31 2 4 6
140  
141 6 ▶ return if (length $year > 2 and $year < 1901);
Branch: 1 branch
BranchTrueFalseTotal
if length $year > 2 and $year < 1901 0 6 6
Condition33%1/3
length $year > 2 and $year < 1901
!ll&&!rl&&r
060
MC/DC0%0/2
length $year > 2 and $year < 1901
length $year > 2 $year < 1901
Truth table33%1/3
A and B
A= length $year > 2B= $year < 1901
ABresult
0X0
100
111
142 6 last TRY;
143 }
144  
145 2 ▶ if ($dtstr =~ s{ \s (\d+) \s* ($sufpat)? \s* ($monpat) }{ }mox) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dtstr =~ s/ \s (\d+) \s* ($sufpat)? \s* ($monpat) / /mox) 0 2 2
146 0 ($month, $day) = ($month{ $3 }, $1);
147 0 last TRY;
148 }
149  
150 2 ▶ if ($dtstr =~ s{ ($monpat) \s* (\d+) \s* ($sufpat)? \s }{ }mox) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dtstr =~ s/ ($monpat) \s* (\d+) \s* ($sufpat)? \s / /mox) 0 2 2
151 0 ($month, $day) = ($month{ $1 }, $2);
152 0 last TRY;
153 }
154  
155 2 ▶ if ($dtstr =~ s{ \s (\d\d) (\d\d) (\d\d) \s }{ }mox) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dtstr =~ s/ \s (\d\d) (\d\d) (\d\d) \s / /mox) 0 2 2
156 0 ($year, $month, $day) = ($3, $2 - 1, $1);
157 }
158 } # TRY
159  
160 8 ▶ if (! defined $year && $dtstr =~ s{ \s (\d{2} (\d{2})?)[\s\.,] }{ }mox) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $year and $dtstr =~ s/ \s (\d{2} (\d{2})?)[\s\.,] / /mox) 0 8 8
Condition66%2/3
not defined $year and $dtstr =~ s/ \s (\d{2} (\d{2})?)[\s\.,] / /mox
!ll&&!rl&&r
620
MC/DC0%0/2
not defined $year and $dtstr =~ s/ \s (\d{2} (\d{2})?)[\s\.,] / /mox
not defined $year $dtstr =~ s/ \s (\d{2} (\d{2})?)[\s\.,] / /mox
Truth table66%2/3
not(A) and B
A= not defined $yearB= $dtstr =~ s/ \s (\d{2} (\d{2})?)[\s\.,] / /mox
ABresult
0X0
100
111
161 0 $year = $1;
162 }
163 }
164  
165 11 ▶ $dst = 1 if ($dtstr =~ s{ \b ($dstpat) \b }{}mox);
Branch: 1 branch
BranchTrueFalseTotal
if $dtstr =~ s/ \b ($dstpat) \b //mox 0 11 11
166  
167 11 ▶ if ($dtstr =~ s{ \s \"? ([a-z]{3,4})
Branch: 2 branches
BranchTrueFalseTotal
if ($dtstr =~ s/ \s \"? ([a-z]{3,4}) ($dstpat|\d+[a-z]*|_[a-z]+)? \"? \s / /mox) { } 3 8 11
elsif ($dtstr =~ s/ \s ([a-z]{3,4})? ([\-\+]?) -? (\d\d?) :? (\d\d)? (00)? \s / /mox) { } 0 8 8
168 ($dstpat|\d+[a-z]*|_[a-z]+)? \"? \s }{ }mox) {
169 3 ▶ $zone = tz_offset( $1 || 0 );
Condition50%1/2
$1 || 0
l!l
30
MC/DC0%0/1
$1 || 0
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
170 3 ▶ $dst = 1 if ($2 && $2 =~ m{ $dstpat }msx);
Branch: 1 branch
BranchTrueFalseTotal
if $2 and $2 =~ / $dstpat /msx 0 3 3
Condition33%1/3
$2 and $2 =~ / $dstpat /msx
!ll&&!rl&&r
300
MC/DC0%0/2
$2 and $2 =~ / $dstpat /msx
$2 $2 =~ / $dstpat /msx
Truth table33%1/3
A and B
A= $2B= $2 =~ / $dstpat /msx
ABresult
0X0
100
111
171  
172 3 ▶ return unless (defined $zone);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $zone 2 1 3
173 }
174 elsif ($dtstr =~ s{ \s ([a-z]{3,4})? ([\-\+]?) -?
175 (\d\d?) :? (\d\d)? (00)? \s }{ }mox) {
176 0 ▶ $zone = tz_offset( $1 || 0 );
Condition0%0/2
$1 || 0
l!l
00
MC/DC0%0/1
$1 || 0
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
177  
178 0 ▶ return unless (defined $zone);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $zone 0 0 0
179  
180 0 $h = "$2$3";
181 0 ▶ $m = defined $4 ? "$2$4" : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $4 ? : 0 0 0
182 0 $zone += 60 * ($m + (60 * $h));
183 }
184  
185 9 ▶ if ($dtstr =~ m{ \S }msx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dtstr =~ / \S /msx) 0 9 9
186 0 ▶ if ($dtstr =~ s{ \A \s*(ut?|z)\s* \z }{}msx) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dtstr =~ s/ \A \s*(ut?|z)\s* \z //msx) { } 0 0 0
elsif ($dtstr =~ s/ \s ([a-z]{3,4})? ([\-\+]?) -? (\d\d?) (\d\d)? (00)? \s / /mox) { } 0 0 0
187 0 $zone = 0;
188 }
189 elsif ($dtstr =~ s{ \s ([a-z]{3,4})? ([\-\+]?) -?
190 (\d\d?) (\d\d)? (00)? \s }{ }mox) {
191 0 ▶ $zone = tz_offset( $1 || 0 );
Condition0%0/2
$1 || 0
l!l
00
MC/DC0%0/1
$1 || 0
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
192  
193 0 ▶ return unless (defined $zone);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $zone 0 0 0
194  
195 0 $h = "$2$3";
196 0 ▶ $m = defined $4 ? "$2$4" : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $4 ? : 0 0 0
197 0 $zone += 60 * ($m + (60 * $h));
198 }
199  
200 0 ▶ return if ($dtstr =~ m{ \S }mox);
Branch: 1 branch
BranchTrueFalseTotal
if $dtstr =~ / \S /mox 0 0 0
201 }
202  
203 9 ▶ if (defined $hh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hh) 6 3 9
204 6 ▶ if ($hh == 12) { $hh = 0 if ($merid == $AM) }
Branch: 3 branches
BranchTrueFalseTotal
if ($hh == 12) { } 1 5 6
elsif ($merid == $PM) { } 0 5 5
if $merid == $AM 0 1 1
205 0 elsif ($merid == $PM) { $hh += 12 }
206 }
207  
208 # This is a feature in the original code RT#53413 and RT#105031
209 # $year -= 1900 if (defined $year && $year > 1900);
210 9 ▶ $zone += 3600 if (defined $zone && $dst);
Branch: 1 branch
BranchTrueFalseTotal
if defined $zone and $dst 0 9 9
Condition33%1/3
defined $zone and $dst
!ll&&!rl&&r
090
MC/DC0%0/2
defined $zone and $dst
defined $zone $dst
Truth table33%1/3
A and B
A= defined $zoneB= $dst
ABresult
0X0
100
111
211 9 ▶ $month = $lt[4] unless (defined $month);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $month 0 9 9
212 9 ▶ $day = $lt[3] unless (defined $day);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $day 0 9 9
213  
214 9 ▶ unless (defined $year) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $year) 0 9 9
215 0 ▶ $year = $month > $lt[4] ? $lt[5] - 1 : $lt[5];
Branch: 1 branch
BranchTrueFalseTotal
$month > $lt[4] ? : 0 0 0
216 }
217  
218 9 ▶ $hh = 0 unless (defined $hh);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hh 3 6 9
219 9 ▶ $mm = 0 unless (defined $mm);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mm 3 6 9
220 9 ▶ $ss = 0 unless (defined $ss);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ss 4 5 9
221 9 ▶ $frac = 0 unless (defined $frac);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $frac 9 0 9
222  
223 9 ▶ return unless ($month <= 11 && $day >= 1 && $day <= 31
Branch: 1 branch
BranchTrueFalseTotal
unless $month <= 11 and $day >= 1 and $day <= 31 and $hh <= 23 and $mm <= 59 and $ss <= 59 0 9 9
Condition33%5/15
$month <= 11 and $day >= 1 and $day <= 31 and $hh <= 23 and $mm <= 59 and $ss <= 59
!ll&&!rl&&r
009
$month <= 11 and $day >= 1 and $day <= 31 and $hh <= 23 and $mm <= 59
!ll&&!rl&&r
009
$month <= 11 and $day >= 1 and $day <= 31 and $hh <= 23
!ll&&!rl&&r
009
$month <= 11 and $day >= 1 and $day <= 31
!ll&&!rl&&r
009
$month <= 11 and $day >= 1
!ll&&!rl&&r
009
MC/DC0%0/6
$month <= 11 and $day >= 1 and $day <= 31 and $hh <= 23 and $mm <= 59 and $ss <= 59
$month <= 11 $day >= 1 $day <= 31 $hh <= 23 $mm <= 59 $ss <= 59
Truth table14%1/7
A and B and C and D and E and F
A= $month <= 11B= $day >= 1C= $day <= 31D= $hh <= 23E= $mm <= 59F= $ss <= 59
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
224 && $hh <= 23 && $mm <= 59 && $ss <= 59);
225  
226 9 ▶ if (defined $zone) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $zone) { } 9 0 9
227 9 $result = eval {
228 9 ▶ local $SIG{__DIE__} = sub {}; # Ick!
Subroutine __ANON__: not called CC=1 SCAR=0.0
229 9 timegm( $ss, $mm, $hh, $day, $month, $year );
230 };
231  
232 9 ▶ return if (! defined $result ||
Branch: 1 branch
BranchTrueFalseTotal
if not defined $result or $result == -1 and join("", $ss, $mm, $hh, $day, $month, $year) ne "595923311169" 0 9 9
Condition33%2/6
not defined $result or $result == -1 and join("", $ss, $mm, $hh, $day, $month, $year) ne "595923311169"
l!l&&r!l&&!r
009
$result == -1 and join("", $ss, $mm, $hh, $day, $month, $year) ne "595923311169"
!ll&&!rl&&r
900
MC/DC0%0/3
not defined $result or $result == -1 and join("", $ss, $mm, $hh, $day, $month, $year) ne "595923311169"
not defined $result $result == -1 join("", $ss, $mm, $hh, $day, $month, $year) ne "595923311169"
Truth table25%1/4
not(A) or B and C
A= not defined $resultB= $result == -1C= join("", $ss, $mm, $hh, $day, $month, $year) ne "595923311169"
ABCresult
1XX1
0111
00X0
0100
233 ($result == -1
234 && (join q(), $ss, $mm, $hh, $day, $month, $year)
235 ne '595923311169'));
236  
237 9 $result -= $zone;
238 }
239 else {
240 0 $result = eval {
241 0 ▶ local $SIG{__DIE__} = sub {}; # Ick!
Subroutine __ANON__: not called CC=1 SCAR=6.9
242 0 timelocal( $ss, $mm, $hh, $day, $month, $year );
243 };
244  
245 0 ▶ return if (! defined $result ||
Branch: 1 branch
BranchTrueFalseTotal
if not defined $result or $result == -1 and join("", $ss, $mm, $hh, $day, $month, $year) ne join("", (localtime -1)[0..5]) 0 0 0
Condition0%0/6
not defined $result or $result == -1 and join("", $ss, $mm, $hh, $day, $month, $year) ne join("", (localtime -1)[0..5])
l!l&&r!l&&!r
000
$result == -1 and join("", $ss, $mm, $hh, $day, $month, $year) ne join("", (localtime -1)[0..5])
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $result or $result == -1 and join("", $ss, $mm, $hh, $day, $month, $year) ne join("", (localtime -1)[0..5])
not defined $result $result == -1 join("", $ss, $mm, $hh, $day, $month, $year) ne join("", (localtime -1)[0..5])
Truth table0%0/4
not(A) or B and C
A= not defined $resultB= $result == -1C= join("", $ss, $mm, $hh, $day, $month, $year) ne join("", (localtime -1)[0..5])
ABCresult
1XX1
0111
00X0
0100
246 ($result == -1
247 && (join q(), $ss, $mm, $hh, $day, $month, $year)
248 ne join q(), (localtime -1)[0 .. 5]));
249 }
250  
251 9 return $result + $frac;
252 }
253  
254 1 ▶sub str2time_piece ($;$) {
Subroutine str2time_piece: called CC=5 SCAR=19.1
Pod documented
255 1 my ($dstr, $zone) = @_; my $time = str2time( $dstr, $zone );
256  
257 1 ▶ defined $time or throw DateTimeCoercion, [ $dstr ];
Branch: 1 branch
BranchTrueFalseTotal
defined $time or &throw(DateTimeCoercion(), [$dstr]) 1 0 1
258  
259 1 ▶ $_time_piece_loaded
Branch: 1 branch
BranchTrueFalseTotal
$_time_piece_loaded or &ensure_class_loaded("Time::Piece") and $_time_piece_loaded = 1 0 1 1
Condition33%2/6
$_time_piece_loaded || &ensure_class_loaded('Time::Piece') && ($_time_piece_loaded = 1)
l!l&&r!l&&!r
010
&ensure_class_loaded("Time::Piece") and $_time_piece_loaded = 1
!ll&&!rl&&r
010
MC/DC0%0/3
$_time_piece_loaded || &ensure_class_loaded('Time::Piece') && ($_time_piece_loaded = 1)
$_time_piece_loaded &ensure_class_loaded("Time::Piece") $_time_piece_loaded = 1
Truth table0%0/4
A || B and C
A= $_time_piece_loadedB= &ensure_class_loaded("Time::Piece")C= $_time_piece_loaded = 1
ABCresult
1XX1
0111
00X0
0100
260 or (ensure_class_loaded 'Time::Piece' and $_time_piece_loaded = TRUE);
261  
262 1 ▶ return $zone ? Time::Piece->gmtime( $time ) : Time::Piece->localtime( $time);
Branch: 1 branch
BranchTrueFalseTotal
$zone ? : 1 0 1
263 }
264  
265 4 ▶sub time2str (;$$$) {
Subroutine time2str: called CC=3 SCAR=11.0
Pod documented
266 4 my ($format, $time, $zone) = @_;
267  
268 4 ▶ $format //= '%Y-%m-%d %H:%M:%S'; $time //= time;
Condition75%3/4
$format //= "%Y-%m-%d %H:%M:%S"
l!l
31
$time //= time
l!l
40
MC/DC100%1/1
$format //= "%Y-%m-%d %H:%M:%S"
$format
MC/DC0%0/1
$time //= time
$time
Truth table100%2/2
A
A= $format
Aresult
11
00
Truth table50%1/2
A
A= $time
Aresult
11
00
269  
270 4 return Date::Format::Generic->time2str( $format, $time, $zone );
271 }
272  
273 19 1;
274  
275 __END__
↑ Summary Usul/IPC.pm »