| 1 | package DateTime::Format::Duration::ConciseHMS; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | our $DATE = '2019-06-19'; # DATE | |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | our $VERSION = '0.001'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | return bless \%args, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | sub format_duration { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_duration: called CC=9 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | my ($self, $dtdur) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | unless (eval { $dtdur->isa('DateTime::Duration') }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | die "'$dtdur' not a DateTime::Duration instance"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | my ($y, $m, $w, $d, $H, $M, $S, $ns) = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | $dtdur->years, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | $dtdur->months, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | $dtdur->weeks, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | $dtdur->days, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | $dtdur->hours, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | $dtdur->minutes, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | $dtdur->seconds, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | $dtdur->nanoseconds, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | $d += $w * 7; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | ▶ | my $has_date = $y || $m || $w || $d; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%6/9
$y || $m || $w || $d
$y or $m or $w
$y or $m
MC/DC25%1/4
$y || $m || $w || $d
$y
$m
$w
$d
Truth table40%2/5
A or B or C || D
A= $yB= $mC= $wD= $d
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | ▶ | my $has_time = $H || $M || $S; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$H || $M || $S
$H or $M
MC/DC33%1/3
$H || $M || $S
$H
$M
$S
Truth table50%2/4
A or B || C
A= $HB= $MC= $S
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | ▶ | join( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$has_time || !$has_date
MC/DC100%2/2
$has_time || !$has_date
$has_time
!$has_date
Truth table100%3/3
A || not(B)
A= $has_timeB= !$has_date
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | " ", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ("${y}y") x !!$y, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ("${m}mo") x !!$m, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ("${d}d") x !!$d, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | sprintf("%02d:%02d:%02d%s", $H, $M, $S, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | $ns ? sprintf(".%03d", $ns/1e6) : "") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ) x !!($has_time || !$has_date), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # ABSTRACT: Format DateTime::Duration object as concise HMS format | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||