| 1 | package Data::Sah::Util::Type::Date; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | #use Log::Any '$log'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Scalar::Util qw(blessed looks_like_number); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | our $DATE = '2024-02-16'; # DATE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | our $DIST = 'Data-Sah'; # DIST | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | our $VERSION = '0.917'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | coerce_date | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | coerce_duration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | our $DATE_MODULE = $ENV{DATA_SAH_DATE_MODULE} // $ENV{PERL_DATE_MODULE} // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | "DateTime"; # XXX change defaults to Time::Piece (core) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
($ENV{"DATA_SAH_DATE_MODULE"} // $ENV{"PERL_DATE_MODULE"}) // "DateTime"
$ENV{"DATA_SAH_DATE_MODULE"} // $ENV{"PERL_DATE_MODULE"}
MC/DC0%0/2
($ENV{"DATA_SAH_DATE_MODULE"} // $ENV{"PERL_DATE_MODULE"}) // "DateTime"
$ENV{"DATA_SAH_DATE_MODULE"}
$ENV{"PERL_DATE_MODULE"}
Truth table33%1/3
A // B
A= $ENV{"DATA_SAH_DATE_MODULE"}B= $ENV{"PERL_DATE_MODULE"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | my $re_ymd = qr/\A([0-9]{4})-([0-9]{2})-([0-9]{2})\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | my $re_ymdThmsZ = qr/\A([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 33 | ▶ | sub coerce_date { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
coerce_date: called CC=44 SCAR=37.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 33 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 33 | ▶ | if (!defined($val)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | return undef; ## no critic: Subroutines::ProhibitExplicitReturnUndef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 30 | ▶ | if ($DATE_MODULE eq 'DateTime') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 10 | require DateTime; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 10 | ▶ | if (blessed($val) && $val->isa('DateTime')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition100%3/3
builtin::blessed($val) and $val->isa("DateTime")
MC/DC100%2/2
builtin::blessed($val) and $val->isa("DateTime")
builtin::blessed($val)
$val->isa("DateTime")
Truth table100%3/3
A and B
A= builtin::blessed($val)B= $val->isa("DateTime")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | return $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ▶ | } elsif (looks_like_number($val) && $val >= 10**8 && $val <= 2**31) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
&looks_like_number($val) and $val >= 100000000 and $val <= "2147483648"
&looks_like_number($val) and $val >= 100000000
MC/DC100%3/3
&looks_like_number($val) and $val >= 100000000 and $val <= "2147483648"
&looks_like_number($val)
$val >= 100000000
$val <= "2147483648"
Truth table100%4/4
A and B and C
A= &looks_like_number($val)B= $val >= 100000000C= $val <= "2147483648"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | return DateTime->from_epoch(epoch => $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } elsif ($val =~ $re_ymd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | my $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | eval { $d = DateTime->new(year=>$1, month=>$2, day=>$3, time_zone=>'UTC') }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | ▶ | return undef if $@; ## no critic: Subroutines::ProhibitExplicitReturnUndef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | return $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } elsif ($val =~ $re_ymdThmsZ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | my $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | eval { $d = DateTime->new(year=>$1, month=>$2, day=>$3, hour=>$4, minute=>$5, second=>$6, time_zone=>'UTC') }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | return undef if $@; ## no critic: Subroutines::ProhibitExplicitReturnUndef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | return $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ▶ | } elsif (blessed($val) && $val->isa('Time::Moment')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
builtin::blessed($val) and $val->isa("Time::Moment")
MC/DC100%2/2
builtin::blessed($val) and $val->isa("Time::Moment")
builtin::blessed($val)
$val->isa("Time::Moment")
Truth table100%3/3
A and B
A= builtin::blessed($val)B= $val->isa("Time::Moment")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | return DateTime->from_epoch(epoch => $val->epoch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ▶ | } elsif (blessed($val) && $val->isa('Time::Piece')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($val) and $val->isa("Time::Piece")
MC/DC50%1/2
builtin::blessed($val) and $val->isa("Time::Piece")
builtin::blessed($val)
$val->isa("Time::Piece")
Truth table66%2/3
A and B
A= builtin::blessed($val)B= $val->isa("Time::Piece")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | return DateTime->from_epoch(epoch => $val->epoch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | return undef; ## no critic: Subroutines::ProhibitExplicitReturnUndef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } elsif ($DATE_MODULE eq 'Time::Moment') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 10 | require Time::Moment; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 10 | ▶ | if (blessed($val) && $val->isa('Time::Moment')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition100%3/3
builtin::blessed($val) and $val->isa("Time::Moment")
MC/DC100%2/2
builtin::blessed($val) and $val->isa("Time::Moment")
builtin::blessed($val)
$val->isa("Time::Moment")
Truth table100%3/3
A and B
A= builtin::blessed($val)B= $val->isa("Time::Moment")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | return $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ▶ | } elsif (looks_like_number($val) && $val >= 10**8 && $val <= 2**31) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
&looks_like_number($val) and $val >= 100000000 and $val <= "2147483648"
&looks_like_number($val) and $val >= 100000000
MC/DC100%3/3
&looks_like_number($val) and $val >= 100000000 and $val <= "2147483648"
&looks_like_number($val)
$val >= 100000000
$val <= "2147483648"
Truth table100%4/4
A and B and C
A= &looks_like_number($val)B= $val >= 100000000C= $val <= "2147483648"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | return Time::Moment->from_epoch(int($val), $val-int($val)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } elsif ($val =~ $re_ymd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | my $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | eval { $d = Time::Moment->new(year=>$1, month=>$2, day=>$3) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | return undef if $@; ## no critic: Subroutines::ProhibitExplicitReturnUndef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | return $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } elsif ($val =~ $re_ymdThmsZ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | my $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | eval { $d = Time::Moment->new(year=>$1, month=>$2, day=>$3, hour=>$4, minute=>$5, second=>$6) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | return undef if $@; ## no critic: Subroutines::ProhibitExplicitReturnUndef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | return $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ▶ | } elsif (blessed($val) && $val->isa('DateTime')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
builtin::blessed($val) and $val->isa("DateTime")
MC/DC100%2/2
builtin::blessed($val) and $val->isa("DateTime")
builtin::blessed($val)
$val->isa("DateTime")
Truth table100%3/3
A and B
A= builtin::blessed($val)B= $val->isa("DateTime")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | return Time::Moment->from_epoch($val->epoch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ▶ | } elsif (blessed($val) && $val->isa('Time::Piece')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($val) and $val->isa("Time::Piece")
MC/DC50%1/2
builtin::blessed($val) and $val->isa("Time::Piece")
builtin::blessed($val)
$val->isa("Time::Piece")
Truth table66%2/3
A and B
A= builtin::blessed($val)B= $val->isa("Time::Piece")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | return Time::Moment->from_epoch($val->epoch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | return undef; ## no critic: Subroutines::ProhibitExplicitReturnUndef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } elsif ($DATE_MODULE eq 'Time::Piece') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 10 | require Time::Piece; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 10 | ▶ | if (blessed($val) && $val->isa('Time::Piece')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition100%3/3
builtin::blessed($val) and $val->isa("Time::Piece")
MC/DC100%2/2
builtin::blessed($val) and $val->isa("Time::Piece")
builtin::blessed($val)
$val->isa("Time::Piece")
Truth table100%3/3
A and B
A= builtin::blessed($val)B= $val->isa("Time::Piece")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | return $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ▶ | } elsif (looks_like_number($val) && $val >= 10**8 && $val <= 2**31) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
&looks_like_number($val) and $val >= 100000000 and $val <= "2147483648"
&looks_like_number($val) and $val >= 100000000
MC/DC100%3/3
&looks_like_number($val) and $val >= 100000000 and $val <= "2147483648"
&looks_like_number($val)
$val >= 100000000
$val <= "2147483648"
Truth table100%4/4
A and B and C
A= &looks_like_number($val)B= $val >= 100000000C= $val <= "2147483648"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | return scalar Time::Piece->gmtime($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } elsif ($val =~ $re_ymd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | my $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | eval { $d = Time::Piece->strptime($val, "%Y-%m-%d") }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | return undef if $@; ## no critic: Subroutines::ProhibitExplicitReturnUndef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | return $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } elsif ($val =~ $re_ymdThmsZ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | my $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | eval { $d = Time::Piece->strptime($val, "%Y-%m-%dT%H:%M:%SZ") }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | return undef if $@; ## no critic: Subroutines::ProhibitExplicitReturnUndef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | return $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ▶ | } elsif (blessed($val) && $val->isa('DateTime')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
builtin::blessed($val) and $val->isa("DateTime")
MC/DC100%2/2
builtin::blessed($val) and $val->isa("DateTime")
builtin::blessed($val)
$val->isa("DateTime")
Truth table100%3/3
A and B
A= builtin::blessed($val)B= $val->isa("DateTime")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | return scalar Time::Piece->gmtime(epoch => $val->epoch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ▶ | } elsif (blessed($val) && $val->isa('Time::Moment')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($val) and $val->isa("Time::Moment")
MC/DC50%1/2
builtin::blessed($val) and $val->isa("Time::Moment")
builtin::blessed($val)
$val->isa("Time::Moment")
Truth table66%2/3
A and B
A= builtin::blessed($val)B= $val->isa("Time::Moment")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | return scalar Time::Piece->gmtime(epoch => $val->epoch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | return undef; ## no critic: Subroutines::ProhibitExplicitReturnUndef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | die "BUG: Unknown Perl date module '$DATE_MODULE'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub coerce_duration { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
coerce_duration: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $val = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if (!defined($val)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return undef; ## no critic: Subroutines::ProhibitExplicitReturnUndef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ▶ | } elsif (blessed($val) && $val->isa('DateTime::Duration')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
builtin::blessed($val) and $val->isa("DateTime::Duration")
MC/DC0%0/2
builtin::blessed($val) and $val->isa("DateTime::Duration")
builtin::blessed($val)
$val->isa("DateTime::Duration")
Truth table0%0/3
A and B
A= builtin::blessed($val)B= $val->isa("DateTime::Duration")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | return $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } elsif ($val =~ /\AP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | (?: ([0-9]+(?:\.[0-9]+)?)Y )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | (?: ([0-9]+(?:\.[0-9]+)?)M )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | (?: ([0-9]+(?:\.[0-9]+)?)W )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | (?: ([0-9]+(?:\.[0-9]+)?)D )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | T | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | (?: ([0-9]+(?:\.[0-9]+)?)H )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | (?: ([0-9]+(?:\.[0-9]+)?)M )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | (?: ([0-9]+(?:\.[0-9]+)?)S )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | \z/x) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | require DateTime::Duration; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | $d = DateTime::Duration->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/14
$1 // 0
$2 // 0
$3 // 0
$4 // 0
$5 // 0
$6 // 0
$7 // 0
MC/DC0%0/1
$1 // 0
$1
MC/DC0%0/1
$2 // 0
$2
MC/DC0%0/1
$3 // 0
$3
MC/DC0%0/1
$4 // 0
$4
MC/DC0%0/1
$5 // 0
$5
MC/DC0%0/1
$6 // 0
$6
MC/DC0%0/1
$7 // 0
$7
Truth table0%0/2
A
A= $1
Truth table0%0/2
A
A= $2
Truth table0%0/2
A
A= $3
Truth table0%0/2
A
A= $4
Truth table0%0/2
A
A= $5
Truth table0%0/2
A
A= $6
Truth table0%0/2
A
A= $7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | years => $1 // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | months => $2 // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | weeks => $3 // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | days => $4 // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | hours => $5 // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | minutes => $6 // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | seconds => $7 // 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | return undef if $@; ## no critic: Subroutines::ProhibitExplicitReturnUndef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | return $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | return undef; ## no critic: Subroutines::ProhibitExplicitReturnUndef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # ABSTRACT: Utility related to date/duration type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||