P.pm

filter: Statementstmt 7.2% 48 / 661 Branchbran 0.0% 0 / 254 Conditioncond 0.0% 0 / 87 MC/DCmcdc 0.0% 0 / 54 Subroutinesub 8.4% 9 / 106 Podpod 100% 1 / 1 totaltotal 4.9% 58 / 1163 CC 160 SCAR 59.0
CC
160
Cov
5%
_coerce_struct
1640.0
_get_year
812.0
_get_hour
306.0
CRAP 366.3
« C/Util.pm ↑ Summary D.pm »
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::P;
4 9 $Time::P::VERSION = '0.024';
5 # ABSTRACT: Parse times from strings.
6  
7 9 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Exporter qw/ import /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Function::Parameters qw/ :lax /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Data::Munge qw/ list2re /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use List::Util qw/ uniq /;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 9 ▶use Time::C::Util qw/ get_fmt_tok get_locale /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 9 ▶use constant DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 9 our @EXPORT = qw/ strptime /;
18  
19  
20 0 my %parser; %parser = (
21 0 ▶ '%A' => fun (:$locale) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 my @weekdays = @{ get_locale(weekdays => $locale) };
23 0 my $re = list2re(@weekdays);
24 0 return qr"(?<A>$re)";
25 0 },
26 0 ▶ '%a' => fun (:$locale) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 my @weekdays_abbr = @{ get_locale(weekdays_abbr => $locale) };
28 0 my $re = list2re(@weekdays_abbr);
29 0 return qr"(?<a>$re)";
30 0 },
31 0 ▶ '%B' => fun (:$locale) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 0 my @months = @{ get_locale(months => $locale) };
33 0 my $re = list2re(@months);
34 0 return qr"(?<B>$re)";
35 0 },
36 0 ▶ '%b' => fun (:$locale) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 0 my @months_abbr = @{ get_locale(months_abbr => $locale) };
38 0 my $re = list2re(@months_abbr);
39 0 return qr"(?<b>$re)";
40 },
41 0 ▶ '%C' => fun () { qr"(?<C>[0-9][0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 0 ▶ '%-C' => fun () { qr"(?<C>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 0 ▶ '%c' => fun (:$locale) { _compile_fmt(get_locale(datetime => $locale), locale => $locale); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 0 ▶ '%D' => fun () {
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 return $parser{'%m'}->(), qr!/!, $parser{'%d'}->(), qr!/!, $parser{'%y'}->();
46 },
47 0 ▶ '%d' => fun () { qr"(?<d>[0-9][0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 ▶ '%-d' => fun () { qr"(?<d>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 0 ▶ '%EC' => fun (:$locale) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
50 0 my @eras = _get_eras(period => $locale);
51 0 ▶ return $parser{'%C'}->() if not @eras;
Branch: 1 branch
BranchTrueFalseTotal
unless @eras 0 0 0
52 0 my $re = list2re(@eras);
53 0 return qr"(?<EC>$re)";
54 0 },
55 0 ▶ '%Ec' => fun (:$locale) { _compile_fmt(get_locale(era_datetime => $locale), locale => $locale); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 0 ▶ '%EX' => fun (:$locale) { _compile_fmt(get_locale(era_time => $locale), locale => $locale); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 ▶ '%Ex' => fun (:$locale) { _compile_fmt(get_locale(era_date => $locale), locale => $locale); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
58 0 ▶ '%EY' => fun (:$locale) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
59 0 my @eras = _get_eras(full => $locale);
60 0 ▶ return $parser{'%Y'}->() if not @eras;
Branch: 1 branch
BranchTrueFalseTotal
unless @eras 0 0 0
61  
62 0 my @ret = map { my $re = join "", _compile_fmt($_, locale => $locale); qr/$re/ } uniq @eras;
63 0 my $full_re = join "|", @ret;
64 0 return qr/$full_re/;
65 },
66 0 ▶ '%Ey' => fun () { qr"(?<Ey>[0-9]+)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 0 ▶ '%e' => fun () { qr"(?:\s(?<e>[0-9])|(?<e>[0-9][0-9]))"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
68 0 ▶ '%-e' => fun () { qr"(?<e>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 0 ▶ '%F' => fun () {
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 0 return $parser{'%Y'}->(), qr/-/, $parser{'%m'}->(), qr/-/, $parser{'%d'}->();
71 },
72 0 ▶ '%G' => fun () { qr"(?<G>[0-9]{4})"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
73 0 ▶ '%-G' => fun () { qr"(?<G>[0-9]{1,4})"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
74 0 ▶ '%g' => fun () { qr"(?<g>[0-9][0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 0 ▶ '%-g' => fun () { qr"(?<g>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 0 ▶ '%H' => fun () { qr"(?<H>[0-9][0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
77 0 ▶ '%-H' => fun () { qr"(?<H>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 0 ▶ '%h' => fun (:$locale) { $parser{'%b'}->(locale => $locale) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
79 0 ▶ '%I' => fun () { qr"(?<I>[0-9][0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
80 0 ▶ '%-I' => fun () { qr"(?<I>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 0 ▶ '%j' => fun () { qr"(?<j>[0-9]{3})"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
82 0 ▶ '%-j' => fun () { qr"(?<j>[0-9]{1,3})"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
83 0 ▶ '%k' => fun () { qr"(?:\s(?<k>[0-9])|(?<k>[0-9][0-9]))"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 0 ▶ '%-k' => fun () { qr"(?<k>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
85 0 ▶ '%l' => fun () { qr"(?:\s(?<l>[0-9])|(?<l>[0-9][0-9]))"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
86 0 ▶ '%-l' => fun () { qr"(?<l>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
87 0 ▶ '%M' => fun () { qr"(?<M>[0-9][0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
88 0 ▶ '%-M' => fun () { qr"(?<M>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
89 0 ▶ '%m' => fun () { qr"(?<m>[0-9][0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 0 ▶ '%-m' => fun () { qr"(?<m>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 0 ▶ '%n' => fun () { qr"\s+"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 0 ▶ '%OC' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
93 0 my @d = @{ get_locale(digits => $locale) };
94 0 ▶ return $parser{'%d'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
95 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %OC." if @d < 100;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 100 0 0 0
96 0 my $re = list2re(@d);
97 0 return qr"(?<OC>$re)";
98 0 },
99 0 ▶ '%Od' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
100 0 my @d = @{ get_locale(digits => $locale) };
101 0 ▶ return $parser{'%d'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
102 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %Od." if @d < 32;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 32 0 0 0
103 0 my $re = list2re(@d);
104 0 return qr"(?<Od>$re)";
105 0 },
106 0 ▶ '%Oe' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
107 0 my @d = @{ get_locale(digits => $locale) };
108 0 ▶ return $parser{'%e'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
109 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %Oe." if @d < 32;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 32 0 0 0
110 0 my $re = list2re(@d);
111 0 return qr"(?<Oe>$re)";
112 0 },
113 0 ▶ '%OH' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
114 0 my @d = @{ get_locale(digits => $locale) };
115 0 ▶ return $parser{'%H'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
116 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %OH." if @d < 24;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 24 0 0 0
117 0 my $re = list2re(@d);
118 0 return qr"(?<OH>$re)";
119 0 },
120 0 ▶ '%OI' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
121 0 my @d = @{ get_locale(digits => $locale) };
122 0 ▶ return $parser{'%I'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
123 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %OI." if @d < 13;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 13 0 0 0
124 0 my $re = list2re(@d);
125 0 return qr"(?<OI>$re)";
126 0 },
127 0 ▶ '%OM' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
128 0 my @d = @{ get_locale(digits => $locale) };
129 0 ▶ return $parser{'%M'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
130 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %OM." if @d < 60;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 60 0 0 0
131 0 my $re = list2re(@d);
132 0 return qr"(?<OM>$re)";
133 0 },
134 0 ▶ '%Om' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
135 0 my @d = @{ get_locale(digits => $locale) };
136 0 ▶ return $parser{'%m'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
137 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %Om." if @d < 13;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 13 0 0 0
138 0 my $re = list2re(@d);
139 0 return qr"(?<Om>$re)";
140 0 },
141 0 ▶ '%Op' => fun (:$locale) { $parser{'%p'}->(locale => $locale); }, # one %c spec in my_MM locale erroneously says %Op instead of %p
Subroutine __ANON__: not called CC=1 SCAR=6.9
142 0 ▶ '%OS' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
143 0 my @d = @{ get_locale(digits => $locale) };
144 0 ▶ return $parser{'%S'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
145 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %OS." if @d < 60;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 60 0 0 0
146 0 my $re = list2re(@d);
147 0 return qr"(?<OS>$re)";
148 0 },
149 0 ▶ '%OU' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
150 0 my @d = @{ get_locale(digits => $locale) };
151 0 ▶ return $parser{'%U'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
152 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %OU." if @d < 54;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 54 0 0 0
153 0 my $re = list2re(@d);
154 0 return qr"(?<OU>$re)";
155 0 },
156 0 ▶ '%Ou' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
157 0 my @d = @{ get_locale(digits => $locale) };
158 0 ▶ return $parser{'%u'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
159 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %Ou." if @d < 8;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 8 0 0 0
160 0 my $re = list2re(@d);
161 0 return qr"(?<Ou>$re)";
162 0 },
163 0 ▶ '%OV' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
164 0 my @d = @{ get_locale(digits => $locale) };
165 0 ▶ return $parser{'%V'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
166 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %OV." if @d < 54;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 54 0 0 0
167 0 my $re = list2re(@d);
168 0 return qr"(?<OV>$re)";
169 0 },
170 0 ▶ '%OW' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
171 0 my @d = @{ get_locale(digits => $locale) };
172 0 ▶ return $parser{'%W'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
173 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %OW." if @d < 54;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 54 0 0 0
174 0 my $re = list2re(@d);
175 0 return qr"(?<OW>$re)";
176 0 },
177 0 ▶ '%Ow' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
178 0 my @d = @{ get_locale(digits => $locale) };
179 0 ▶ return $parser{'%w'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
180 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %Ow." if @d < 7;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 7 0 0 0
181 0 my $re = list2re(@d);
182 0 return qr"(?<Ow>$re)";
183 0 },
184 0 ▶ '%Oy' => fun (:$locale) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
185 0 my @d = @{ get_locale(digits => $locale) };
186 0 ▶ return $parser{'%y'}->() if not @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 0 0 0
187 0 ▶ croak "Not enough digits in alt_digits for $locale to represent %Oy." if @d < 100;
Branch: 1 branch
BranchTrueFalseTotal
if @d < 100 0 0 0
188 0 my $re = list2re(@d);
189 0 return qr"(?<Oy>$re)";
190 0 },
191 0 ▶ '%P' => fun (:$locale) { $parser{'%p'}->(locale => $locale); }, # a few %r specs in some locales erroneously say %P instead of %p (wal_ET, ur_PK, pa_PK, iw_IL, he_IL, en_GB, dv_MV, cy_GB)
Subroutine __ANON__: not called CC=1 SCAR=6.9
192 0 ▶ '%p' => fun (:$locale) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
193 0 my @am_pm = @{ get_locale(am_pm => $locale) };
194 0 ▶ return () unless @am_pm;
Branch: 1 branch
BranchTrueFalseTotal
unless @am_pm 0 0 0
195 0 my $re = list2re(@am_pm);
196 0 return qr"(?<p>$re)";
197 0 },
198 0 ▶ '%X' => fun (:$locale) { _compile_fmt(get_locale(time => $locale), locale => $locale); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
199 0 ▶ '%x' => fun (:$locale) { _compile_fmt(get_locale(date => $locale), locale => $locale); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
200 0 ▶ '%R' => fun () {
Subroutine __ANON__: not called CC=1 SCAR=6.9
201 0 return $parser{'%H'}->(), qr/:/, $parser{'%M'}->();
202 0 },
203 0 ▶ '%r' => fun (:$locale) { _compile_fmt(get_locale(time_ampm => $locale), locale => $locale); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
204 0 ▶ '%S' => fun () { qr"(?<S>[0-9][0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
205 0 ▶ '%-S' => fun () { qr"(?<S>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
206 0 ▶ '%s' => fun () { qr"\s*(?<s>[0-9]+)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
207 0 ▶ '%T' => fun () {
Subroutine __ANON__: not called CC=1 SCAR=6.9
208 0 return $parser{'%H'}->(), qr/:/, $parser{'%M'}->(), qr/:/, $parser{'%S'}->();
209 },
210 0 ▶ '%t' => fun () { qr"\s+"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
211 0 ▶ '%U' => fun () { qr"(?<U>[0-9][0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
212 0 ▶ '%-U' => fun () { qr"(?<U>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
213 0 ▶ '%u' => fun () { qr"(?<u>[0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
214 0 ▶ '%V' => fun () { qr"(?<V>[0-9][0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
215 0 ▶ '%-V' => fun () { qr"(?<V>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
216 0 ▶ '%v' => fun (:$locale) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
217 0 return $parser{'%e'}->(), qr/-/, $parser{'%b'}->(locale => $locale), qr/-/, $parser{'%Y'}->()
218 },
219 0 ▶ '%W' => fun () { qr"(?<W>[0-9][0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
220 0 ▶ '%-W' => fun () { qr"(?<W>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
221 0 ▶ '%w' => fun () { qr"(?<w>[0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
222 0 ▶ '%Y' => fun () { qr"(?<Y>-?[0-9]{4})"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
223 0 ▶ '%-Y' => fun () { qr"(?<Y>-?[0-9]{1,4})"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
224 0 ▶ '%y' => fun () { qr"(?<y>[0-9][0-9])"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
225 0 ▶ '%-y' => fun () { qr"(?<y>[0-9][0-9]?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
226 0 ▶ '%Z' => fun () { qr"(?<Z>\S+)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
227 0 ▶ '%z' => fun () { qr"(?<z>[-+][0-9][0-9](?::?[0-9][0-9])?)"; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
228 0 ▶ '%%' => fun () { qr"%"; },
Subroutine __ANON__: not called CC=1 SCAR=1.2
229 );
230  
231  
232 0 ▶fun strptime ($str, $fmt, :$locale = 'C', :$strict = 1, :$struct = {}) {
Subroutine strptime: not called CC=9 SCAR=45.0
Pod documented
Branch: 3 branches
BranchTrueFalseTotal
exists ${__rest}{'locale'} ? : 0 0 0
exists ${__rest}{'strict'} ? : 0 0 0
exists ${__rest}{'struct'} ? : 0 0 0
233 0 my %parse = ();
234  
235 0 my @res = _compile_fmt($fmt, locale => $locale);
236  
237 0 ▶ croak "Could not match '%s' using '%s'.", $str, $fmt if not @res;
Branch: 1 branch
BranchTrueFalseTotal
unless @res 0 0 0
238  
239 0 ▶ @res = (qr/^/, @res, qr/$/) if $strict;
Branch: 1 branch
BranchTrueFalseTotal
if $strict 0 0 0
240  
241 0 my $re;
242 0 ▶ while (defined ($re = shift @res) and $str =~ m/\G$re/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($re = shift @res) and $str =~ /\G$re/cg) 0 0 0
Condition0%0/3
defined($re = shift @res) and $str =~ /\G$re/cg
!ll&&!rl&&r
000
MC/DC0%0/2
defined($re = shift @res) and $str =~ /\G$re/cg
defined($re = shift @res) $str =~ /\G$re/cg
Truth table0%0/3
A and B
A= defined($re = shift @res)B= $str =~ /\G$re/cg
ABresult
0X0
100
111
243 0 warn "matched with $re\n" if DEBUG;
244 0 %parse = (%parse, %+);
245 }
246  
247 0 ▶ if (@res) {
Branch: 1 branch
BranchTrueFalseTotal
if (@res) 0 0 0
248 0 croak sprintf "Could not match '%s' using '%s'. Match failed at position %d (%s) while trying to match with /%s/.", $str, $fmt, pos($str), substr($str, pos($str)), $re;
249 }
250  
251 0 $struct = { %$struct, _coerce_struct(\%parse, $struct, locale => $locale) };
252  
253 0 return %$struct;
254 9 }
255  
256 0 ▶fun _compile_fmt ($fmt, :$locale) {
Subroutine _compile_fmt: not called CC=4 SCAR=30.0
257 0 my @res = ();
258  
259 0 my $pos = 0;
260  
261 # _get_tok will increment $pos for us
262 0 ▶ while (defined(my $tok = get_fmt_tok($fmt, $pos))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $tok = get_fmt_tok($fmt, $pos))) 0 0 0
263 0 ▶ if (exists $parser{$tok}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $parser{$tok}) { } 0 0 0
elsif ($tok =~ /^%/) { } 0 0 0
264 0 my @p_res = $parser{$tok}->(locale => $locale);
265 0 warn "pushing @p_res to list\n" if DEBUG;
266 0 push @res, @p_res;
267 } elsif ($tok =~ /^%/) {
268 0 croak "Unsupported format specifier: $tok";
269 } else {
270 0 my $re = qr/\Q$tok\E/;
271 0 warn "pushing $re to list\n" if DEBUG;
272 0 push @res, $re;
273 }
274 }
275  
276 0 warn "returning @res\n" if DEBUG;
277 0 return @res;
278 9 }
279  
280 0 ▶fun _get_mday ($struct, :$locale) {
Subroutine _get_mday: not called CC=6 SCAR=37.4
281 0 my $mday = $struct->{'d'};
282 0 ▶ if (not defined $mday) { $mday = $struct->{'e'}; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mday) 0 0 0
283 0 ▶ if (not defined $mday and defined(my $Od = $struct->{Od})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $mday and defined(my $Od = $struct->{"Od"})) 0 0 0
Condition0%0/3
not defined $mday and defined(my $Od = $struct->{"Od"})
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $mday and defined(my $Od = $struct->{"Od"})
not defined $mday defined(my $Od = $struct->{"Od"})
Truth table0%0/3
not(A) and B
A= not defined $mdayB= defined(my $Od = $struct->{"Od"})
ABresult
0X0
100
111
284 0 my @d = @{ get_locale(digits => $locale) };
285 0 $mday = _get_index($Od, @d);
286 }
287 0 ▶ if (not defined $mday and defined(my $Oe = $struct->{Oe})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $mday and defined(my $Oe = $struct->{"Oe"})) 0 0 0
Condition0%0/3
not defined $mday and defined(my $Oe = $struct->{"Oe"})
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $mday and defined(my $Oe = $struct->{"Oe"})
not defined $mday defined(my $Oe = $struct->{"Oe"})
Truth table0%0/3
not(A) and B
A= not defined $mdayB= defined(my $Oe = $struct->{"Oe"})
ABresult
0X0
100
111
288 0 my @d = @{ get_locale(digits => $locale) };
289 0 $mday = _get_index($Oe, @d);
290 }
291  
292 0 return $mday;
293 9 }
294  
295 0 ▶fun _get_year ($struct, :$locale) {
Subroutine _get_year: not called CC=28 SCAR=67.0
296 0 my $wyear = 0;
297 0 my $year = $struct->{'Y'};
298 0 ▶ if (not defined $year) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $year) 0 0 0
299 0 ▶ if (defined $struct->{'G'}) {
Branch: 4 branches
BranchTrueFalseTotal
if (defined $struct->{'G'}) { } 0 0 0
elsif (defined $struct->{'C'}) { } 0 0 0
elsif (defined $struct->{'y'}) { } 0 0 0
elsif (defined $struct->{'g'}) { } 0 0 0
300 0 $year = $struct->{'G'};
301 0 $wyear = 1;
302 } elsif (defined $struct->{'C'}) {
303 0 $year = $struct->{'C'} * 100;
304 0 ▶ $year += $struct->{'y'} if defined $struct->{'y'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $struct->{"y"} 0 0 0
305 0 ▶ if (defined $struct->{'g'} and not defined $struct->{'y'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $struct->{"g"} and not defined $struct->{"y"}) 0 0 0
Condition0%0/3
defined $struct->{"g"} and not defined $struct->{"y"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $struct->{"g"} and not defined $struct->{"y"}
defined $struct->{"g"} not defined $struct->{"y"}
Truth table0%0/3
A and not(B)
A= defined $struct->{"g"}B= not defined $struct->{"y"}
ABresult
0X0
100
111
306 0 $year += $struct->{'g'};
307 0 $wyear = 1;
308 }
309 } elsif (defined $struct->{'y'}) {
310 0 $year = $struct->{'y'} + 1900;
311 0 require Time::C;
312 0 ▶ if ($year < (Time::C->now_utc()->year - 50)) { $year += 100; }
Branch: 1 branch
BranchTrueFalseTotal
if ($year < "Time::C"->now_utc->year - 50) 0 0 0
313 } elsif (defined $struct->{'g'}) {
314 0 $year = $struct->{'g'} + 1900;
315 0 require Time::C;
316 0 ▶ if ($year < (Time::C->now_utc()->year - 50)) { $year += 100; }
Branch: 1 branch
BranchTrueFalseTotal
if ($year < "Time::C"->now_utc->year - 50) 0 0 0
317 0 $wyear = 1;
318 }
319 }
320 0 ▶ if (not defined $year) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $year) 0 0 0
321 0 my $Ey = $struct->{Ey};
322 0 my $EC = $struct->{EC};
323  
324 0 ▶ if (defined $EC) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $EC) { } 0 0 0
elsif (defined $Ey) { } 0 0 0
325 0 my @eras = @{ get_locale(era => $locale) };
326 0 foreach my $era (@eras) {
327 0 my @fields = split /:/, $era;
328 0 ▶ next if $EC ne $fields[4];
Branch: 1 branch
BranchTrueFalseTotal
if $EC ne $fields[4] 0 0 0
329  
330 0 my %s = strptime($fields[2], "%-Y/%m/%d");
331 0 ▶ $s{year}++ if $s{year} < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $s{"year"} < 1 0 0 0
332 0 $year = $s{year};
333 0 ▶ $year += $Ey - $fields[1] if defined $Ey;
Branch: 1 branch
BranchTrueFalseTotal
if defined $Ey 0 0 0
334 0 ▶ $year-- if not defined $Ey;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Ey 0 0 0
335 0 last;
336 }
337 } elsif (defined $Ey) {
338 0 my @eras = @{ get_locale(era => $locale) };
339 0 foreach my $era (@eras) {
340 0 my @fields = split /:/, $era;
341  
342 0 my %s = strptime($fields[2], "%-Y/%m/%d");
343 0 ▶ $s{year}++ if $s{year} < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $s{"year"} < 1 0 0 0
344 0 require Time::C;
345 0 ▶ next if $s{year} > Time::C->now_utc()->year;
Branch: 1 branch
BranchTrueFalseTotal
if $s{"year"} > "Time::C"->now_utc->year 0 0 0
346  
347 0 $year = $s{year} + $Ey - $fields[1];
348 0 last;
349 }
350 }
351 }
352 0 ▶ if (not defined $year and defined(my $Oy = $struct->{Oy})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $year and defined(my $Oy = $struct->{"Oy"})) 0 0 0
Condition0%0/3
not defined $year and defined(my $Oy = $struct->{"Oy"})
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $year and defined(my $Oy = $struct->{"Oy"})
not defined $year defined(my $Oy = $struct->{"Oy"})
Truth table0%0/3
not(A) and B
A= not defined $yearB= defined(my $Oy = $struct->{"Oy"})
ABresult
0X0
100
111
353 0 my @d = @{ get_locale(digits => $locale) };
354 0 ▶ if (defined(my $C = $struct->{C})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $C = $struct->{'C'})) { } 0 0 0
elsif (defined(my $OC = $struct->{'OC'})) { } 0 0 0
355 0 $year = $C * 100;
356 } elsif (defined(my $OC = $struct->{OC})) {
357 0 $year = _get_index($OC, @d) * 100;
358 } else {
359 0 $year = 1900;
360 }
361 0 $year += _get_index($Oy, @d);
362 0 ▶ if (not defined $struct->{C}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $struct->{"C"}) 0 0 0
363 0 require Time::C;
364 0 ▶ if ($year < (Time::C->now_utc()->year - 50)) { $year += 100; }
Branch: 1 branch
BranchTrueFalseTotal
if ($year < "Time::C"->now_utc->year - 50) 0 0 0
365 }
366 }
367  
368 0 return ($year, $wyear);
369 9 }
370  
371 0 ▶fun _get_wday($struct, :$locale) {
Subroutine _get_wday: not called CC=10 SCAR=47.0
372 0 ▶ my $wday = $struct->{'u'} // $struct->{'w'};
Condition0%0/3
$struct->{"u"} // $struct->{"w"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$struct->{"u"} // $struct->{"w"}
$struct->{"u"} $struct->{"w"}
Truth table0%0/3
A // B
A= $struct->{"u"}B= $struct->{"w"}
ABresult
1X1
011
000
373  
374 0 ▶ if (not defined $wday) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $wday) 0 0 0
375 0 ▶ if (defined $struct->{'A'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $struct->{'A'}) { } 0 0 0
elsif (defined $struct->{'a'}) { } 0 0 0
376 0 $wday = _get_index($struct->{'A'}, @{ get_locale(weekdays => $locale) });
377 } elsif (defined $struct->{'a'}) {
378 0 $wday = _get_index($struct->{'a'}, @{ get_locale(weekdays_abbr => $locale) });
379 }
380 }
381 0 ▶ if (not defined $wday) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $wday) 0 0 0
382 0 ▶ if (defined(my $Ou = $struct->{Ou})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $Ou = $struct->{'Ou'})) { } 0 0 0
elsif (defined(my $Ow = $struct->{'Ow'})) { } 0 0 0
383 0 my @d = @{ get_locale(digits => $locale) };
384 0 $wday = _get_index($Ou, @d);
385 } elsif (defined(my $Ow = $struct->{Ow})) {
386 0 my @d = @{ get_locale(digits => $locale) };
387 0 $wday = _get_index($Ow, @d);
388 }
389 }
390 0 ▶ $wday = 7 if defined $wday and $wday == 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $wday and $wday == 0 0 0 0
Condition0%0/3
defined $wday and $wday == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $wday and $wday == 0
defined $wday $wday == 0
Truth table0%0/3
A and B
A= defined $wdayB= $wday == 0
ABresult
0X0
100
111
391  
392 0 return $wday;
393 9 }
394  
395 0 ▶fun _get_u_week ($struct, :$locale) {
Subroutine _get_u_week: not called CC=3 SCAR=24.8
396 0 my $u_week = $struct->{U};
397  
398 0 ▶ if (not defined $u_week and defined(my $OU = $struct->{OU})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $u_week and defined(my $OU = $struct->{"OU"})) 0 0 0
Condition0%0/3
not defined $u_week and defined(my $OU = $struct->{"OU"})
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $u_week and defined(my $OU = $struct->{"OU"})
not defined $u_week defined(my $OU = $struct->{"OU"})
Truth table0%0/3
not(A) and B
A= not defined $u_weekB= defined(my $OU = $struct->{"OU"})
ABresult
0X0
100
111
399 0 my @d = @{ get_locale(digits => $locale) };
400 0 $u_week = _get_index($OU, @d);
401 }
402  
403 0 return $u_week;
404 9 }
405  
406 0 ▶fun _get_w_week ($struct, :$locale) {
Subroutine _get_w_week: not called CC=3 SCAR=24.8
407 0 my $w_week = $struct->{W};
408  
409 0 ▶ if (not defined $w_week and defined(my $OW = $struct->{OW})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $w_week and defined(my $OW = $struct->{"OW"})) 0 0 0
Condition0%0/3
not defined $w_week and defined(my $OW = $struct->{"OW"})
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $w_week and defined(my $OW = $struct->{"OW"})
not defined $w_week defined(my $OW = $struct->{"OW"})
Truth table0%0/3
not(A) and B
A= not defined $w_weekB= defined(my $OW = $struct->{"OW"})
ABresult
0X0
100
111
410 0 my @d = @{ get_locale(digits => $locale) };
411 0 $w_week = _get_index($OW, @d);
412 }
413  
414 0 return $w_week;
415 9 }
416  
417 0 ▶fun _get_v_week ($struct, :$locale) {
Subroutine _get_v_week: not called CC=3 SCAR=24.8
418 0 my $v_week = $struct->{V};
419  
420 0 ▶ if (not defined $v_week and defined(my $OV = $struct->{OV})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $v_week and defined(my $OV = $struct->{"OV"})) 0 0 0
Condition0%0/3
not defined $v_week and defined(my $OV = $struct->{"OV"})
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $v_week and defined(my $OV = $struct->{"OV"})
not defined $v_week defined(my $OV = $struct->{"OV"})
Truth table0%0/3
not(A) and B
A= not defined $v_weekB= defined(my $OV = $struct->{"OV"})
ABresult
0X0
100
111
421 0 my @d = @{ get_locale(digits => $locale) };
422 0 $v_week = _get_index($OV, @d);
423 }
424  
425 0 return $v_week;
426 9 }
427  
428 0 ▶fun _get_month ($struct, :$locale) {
Subroutine _get_month: not called CC=6 SCAR=37.4
429 0 my $month = $struct->{'m'};
430 0 ▶ if (not defined $month) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $month) 0 0 0
431 0 ▶ if (defined $struct->{'B'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $struct->{'B'}) { } 0 0 0
elsif (defined $struct->{'b'}) { } 0 0 0
432 0 $month = _get_index($struct->{'B'}, @{ get_locale(months => $locale) }) + 1;
433 } elsif (defined $struct->{'b'}) {
434 0 $month = _get_index($struct->{'b'}, @{ get_locale(months_abbr => $locale) }) + 1;
435 }
436 }
437 0 ▶ if (not defined $month and defined(my $Om = $struct->{Om})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $month and defined(my $Om = $struct->{"Om"})) 0 0 0
Condition0%0/3
not defined $month and defined(my $Om = $struct->{"Om"})
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $month and defined(my $Om = $struct->{"Om"})
not defined $month defined(my $Om = $struct->{"Om"})
Truth table0%0/3
not(A) and B
A= not defined $monthB= defined(my $Om = $struct->{"Om"})
ABresult
0X0
100
111
438 0 my @d = @{ get_locale(digits => $locale) };
439 0 $month = _get_index($Om, @d);
440 }
441  
442 0 return $month;
443 9 }
444  
445 0 ▶fun _get_hour ($struct, :$locale) {
Subroutine _get_hour: not called CC=17 SCAR=57.2
446 0 my $hour = $struct->{'H'};
447 0 ▶ if (not defined $hour) { $hour = $struct->{'k'}; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hour) 0 0 0
448 0 ▶ if (not defined $hour) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hour) 0 0 0
449 0 ▶ $hour = $struct->{'I'} // $struct->{'l'};
Condition0%0/3
$struct->{"I"} // $struct->{"l"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$struct->{"I"} // $struct->{"l"}
$struct->{"I"} $struct->{"l"}
Truth table0%0/3
A // B
A= $struct->{"I"}B= $struct->{"l"}
ABresult
1X1
011
000
450 0 ▶ if (defined $hour and length $struct->{'p'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hour and length $struct->{"p"}) 0 0 0
Condition0%0/3
defined $hour and length $struct->{"p"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hour and length $struct->{"p"}
defined $hour length $struct->{"p"}
Truth table0%0/3
A and B
A= defined $hourB= length $struct->{"p"}
ABresult
0X0
100
111
451 0 ▶ if (_get_index($struct->{'p'}, @{ get_locale(am_pm => $locale) })) {
Branch: 1 branch
BranchTrueFalseTotal
if (_get_index($struct->{'p'}, @{get_locale('am_pm', $locale);})) { } 0 0 0
452 # PM
453 0 ▶ if ($hour < 12) { $hour += 12; }
Branch: 1 branch
BranchTrueFalseTotal
if ($hour < 12) 0 0 0
454 } else {
455 # AM
456 0 ▶ if ($hour == 12) { $hour = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($hour == 12) 0 0 0
457 }
458 }
459 }
460  
461 0 ▶ if (not defined $hour and defined(my $OH = $struct->{OH})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $hour and defined(my $OH = $struct->{'OH'})) { } 0 0 0
elsif (not defined $hour and defined(my $OI = $struct->{'OI'})) { } 0 0 0
Condition0%0/3
not defined $hour and defined(my $OH = $struct->{"OH"})
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $hour and defined(my $OH = $struct->{"OH"})
not defined $hour defined(my $OH = $struct->{"OH"})
Truth table0%0/3
not(A) and B
A= not defined $hourB= defined(my $OH = $struct->{"OH"})
ABresult
0X0
100
111
462 0 my @d = @{ get_locale(digits => $locale) };
463 0 $hour = _get_index($OH, @d);
464 ▶ } elsif (not defined $hour and defined(my $OI = $struct->{OI})) {
Condition0%0/3
not defined $hour and defined(my $OI = $struct->{"OI"})
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $hour and defined(my $OI = $struct->{"OI"})
not defined $hour defined(my $OI = $struct->{"OI"})
Truth table0%0/3
not(A) and B
A= not defined $hourB= defined(my $OI = $struct->{"OI"})
ABresult
0X0
100
111
465 0 my @d = @{ get_locale(digits => $locale) };
466 0 $hour = _get_index($OI, @d);
467 0 ▶ if (length $struct->{p}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $struct->{"p"}) 0 0 0
468 0 ▶ if (_get_index($struct->{p}, @{ get_locale(am_pm => $locale) })) {
Branch: 1 branch
BranchTrueFalseTotal
if (_get_index($struct->{'p'}, @{get_locale('am_pm', $locale);})) { } 0 0 0
469 # PM
470 0 ▶ if ($hour < 12) { $hour += 12; }
Branch: 1 branch
BranchTrueFalseTotal
if ($hour < 12) 0 0 0
471 } else {
472 # AM
473 0 ▶ if ($hour == 12) { $hour = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($hour == 12) 0 0 0
474 }
475 }
476 }
477  
478 0 return $hour;
479 9 }
480  
481 0 ▶fun _get_minute ($struct, :$locale) {
Subroutine _get_minute: not called CC=3 SCAR=24.8
482 0 my $min = $struct->{'M'};
483  
484 0 ▶ if (not defined $min and defined(my $OM = $struct->{OM})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $min and defined(my $OM = $struct->{"OM"})) 0 0 0
Condition0%0/3
not defined $min and defined(my $OM = $struct->{"OM"})
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $min and defined(my $OM = $struct->{"OM"})
not defined $min defined(my $OM = $struct->{"OM"})
Truth table0%0/3
not(A) and B
A= not defined $minB= defined(my $OM = $struct->{"OM"})
ABresult
0X0
100
111
485 0 my @d = @{ get_locale(digits => $locale) };
486 0 $min = _get_index($OM, @d);
487 }
488  
489 0 return $min;
490 9 }
491  
492 0 ▶fun _get_second ($struct, :$locale) {
Subroutine _get_second: not called CC=3 SCAR=24.8
493 0 my $sec = $struct->{'S'};
494  
495 0 ▶ if (not defined $sec and defined(my $OS = $struct->{OS})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $sec and defined(my $OS = $struct->{"OS"})) 0 0 0
Condition0%0/3
not defined $sec and defined(my $OS = $struct->{"OS"})
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $sec and defined(my $OS = $struct->{"OS"})
not defined $sec defined(my $OS = $struct->{"OS"})
Truth table0%0/3
not(A) and B
A= not defined $secB= defined(my $OS = $struct->{"OS"})
ABresult
0X0
100
111
496 0 my @d = @{ get_locale(digits => $locale) };
497 0 $sec = _get_index($OS, @d);
498 }
499  
500 0 return $sec;
501 9 }
502  
503 0 ▶fun _coerce_struct ($struct, $orig, :$locale) {
Subroutine _coerce_struct: not called CC=40 SCAR=74.0
504 # First, if we know the epoch, great
505 0 my $epoch = $struct->{'s'};
506  
507 # Then set up as many date bits we know about
508 # year + day of year
509 # year + month + day of month
510 # year + week + day of week
511  
512 0 my ($year, $wyear) = _get_year($struct, locale => $locale);
513  
514 0 my $yday = $struct->{'j'};
515  
516 0 my $month = _get_month($struct, locale => $locale);
517  
518 0 my $mday = _get_mday($struct, locale => $locale);
519  
520 0 my $u_week = _get_u_week($struct, locale => $locale);
521 0 my $w_week = _get_w_week($struct, locale => $locale);
522 0 my $v_week = _get_v_week($struct, locale => $locale);
523  
524 0 my $wday = _get_wday($struct, locale => $locale);
525  
526 0 ▶ if (not defined $w_week and defined $u_week) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $w_week and defined $u_week) 0 0 0
Condition0%0/3
not defined $w_week and defined $u_week
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $w_week and defined $u_week
not defined $w_week defined $u_week
Truth table0%0/3
not(A) and B
A= not defined $w_weekB= defined $u_week
ABresult
0X0
100
111
527 0 $w_week = $u_week;
528 0 ▶ if (not defined $wday) { $wday = 7; } # if no wday defined, should set to first day of week, and since the u_week starts at sunday, wday = 7
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $wday) 0 0 0
529 0 ▶ $w_week-- if $wday == 7;
Branch: 1 branch
BranchTrueFalseTotal
if $wday == 7 0 0 0
530 }
531  
532 0 ▶ if (not defined $v_week and defined $w_week) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $v_week and defined $w_week) 0 0 0
Condition0%0/3
not defined $v_week and defined $w_week
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $v_week and defined $w_week
not defined $v_week defined $w_week
Truth table0%0/3
not(A) and B
A= not defined $v_weekB= defined $w_week
ABresult
0X0
100
111
533 0 ▶ if ($wyear) { croak "Can't strptime a %G/%g year with a %W/%U week"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($wyear) 0 0 0
534  
535 0 require Time::C;
536 0 ▶ my $t = Time::C->new($year // $orig->{year} // Time::C->now_utc->year);
Condition0%0/6
($year // $orig->{"year"}) // "Time::C"->now_utc->year
l!l&&r!l&&!r
000
$year // $orig->{"year"}
l!l&&r!l&&!r
000
MC/DC0%0/3
($year // $orig->{"year"}) // "Time::C"->now_utc->year
$year $orig->{"year"} "Time::C"->now_utc->year
Truth table0%0/4
A // B // C
A= $yearB= $orig->{"year"}C= "Time::C"->now_utc->year
ABCresult
1XX1
01X1
0011
0000
537 0 $v_week = $w_week;
538 0 ▶ if (($t->day_of_week > 1) and ($t->day_of_week < 5)) { $v_week++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($t->day_of_week > 1 and $t->day_of_week < 5) 0 0 0
Condition0%0/3
$t->day_of_week > 1 and $t->day_of_week < 5
!ll&&!rl&&r
000
MC/DC0%0/2
$t->day_of_week > 1 and $t->day_of_week < 5
$t->day_of_week > 1 $t->day_of_week < 5
Truth table0%0/3
A and B
A= $t->day_of_week > 1B= $t->day_of_week < 5
ABresult
0X0
100
111
539 }
540  
541 0 ▶ if ($wyear and defined $v_week and $v_week > 1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($wyear and defined $v_week and $v_week > 1) { } 0 0 0
elsif (defined $v_week and $v_week > 1 and defined $year) { } 0 0 0
elsif (defined $v_week and $v_week > 1 and defined $orig->{'year'}) { } 0 0 0
Condition0%0/6
$wyear and defined $v_week and $v_week > 1
!ll&&!rl&&r
000
$wyear and defined $v_week
!ll&&!rl&&r
000
MC/DC0%0/3
$wyear and defined $v_week and $v_week > 1
$wyear defined $v_week $v_week > 1
Truth table0%0/4
A and B and C
A= $wyearB= defined $v_weekC= $v_week > 1
ABCresult
0XX0
10X0
1100
1111
542 0 require Time::C;
543 0 $year = Time::C->mktime(year => $year, week => $v_week)->year;
544 ▶ } elsif (defined $v_week and $v_week > 1 and defined $year) {
Condition0%0/6
defined $v_week and $v_week > 1 and defined $year
!ll&&!rl&&r
000
defined $v_week and $v_week > 1
!ll&&!rl&&r
000
MC/DC0%0/3
defined $v_week and $v_week > 1 and defined $year
defined $v_week $v_week > 1 defined $year
Truth table0%0/4
A and B and C
A= defined $v_weekB= $v_week > 1C= defined $year
ABCresult
0XX0
10X0
1100
1111
545 0 require Time::C;
546 0 ▶ if (Time::C->mktime(year => $year, week => $v_week)->year == $year + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Time::C"->mktime("year", $year, "week", $v_week)->year == $year + 1) 0 0 0
547 0 ▶ $year-- if not defined $month;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $month 0 0 0
548 }
549 ▶ } elsif (defined $v_week and $v_week > 1 and defined $orig->{year}) {
Condition0%0/6
defined $v_week and $v_week > 1 and defined $orig->{"year"}
!ll&&!rl&&r
000
defined $v_week and $v_week > 1
!ll&&!rl&&r
000
MC/DC0%0/3
defined $v_week and $v_week > 1 and defined $orig->{"year"}
defined $v_week $v_week > 1 defined $orig->{"year"}
Truth table0%0/4
A and B and C
A= defined $v_weekB= $v_week > 1C= defined $orig->{"year"}
ABCresult
0XX0
10X0
1100
1111
550 0 require Time::C;
551 0 ▶ if (Time::C->mktime(year => $orig->{year}, week => $v_week)->year == $orig->{year} + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Time::C"->mktime("year", $orig->{"year"}, "week", $v_week)->year == $orig->{"year"} + 1) 0 0 0
552 0 ▶ $year = $orig->{year} - 1 if not defined $month;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $month 0 0 0
553 }
554 }
555  
556 # Next try to set up time bits -- these are pretty easy in comparison
557  
558 0 my $hour = _get_hour($struct, locale => $locale);
559  
560 0 my $min = _get_minute($struct, locale => $locale);
561  
562 0 my $sec = _get_second($struct, locale => $locale);
563  
564 # And last see if we have some timezone or at least offset info
565  
566 0 my $tz = $struct->{'Z'}; # should verify that it's a useful tz
567 0 ▶ if (defined $tz) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tz) 0 0 0
568 0 require Time::C;
569 0 ▶ undef $tz if not defined eval { Time::C->now($tz); };
Branch: 1 branch
BranchTrueFalseTotal
unless defined eval { do { "Time::C"->now($tz) } } 0 0 0
570 }
571  
572 0 my $offset = $struct->{'z'};
573  
574 0 ▶ my $offset_n = defined $offset ? _offset_to_minutes($offset) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $offset ? : 0 0 0
575  
576 0 my %struct = ();
577  
578 0 ▶ $struct{second} = $sec if defined $sec;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sec 0 0 0
579 0 ▶ $struct{minute} = $min if defined $min;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min 0 0 0
580 0 ▶ $struct{hour} = $hour if defined $hour;
Branch: 1 branch
BranchTrueFalseTotal
if defined $hour 0 0 0
581 0 ▶ $struct{mday} = $mday if defined $mday;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mday 0 0 0
582 0 ▶ $struct{month} = $month if defined $month;
Branch: 1 branch
BranchTrueFalseTotal
if defined $month 0 0 0
583 0 ▶ $struct{week} = $v_week if defined $v_week;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v_week 0 0 0
584 0 ▶ $struct{wday} = $wday if defined $wday;
Branch: 1 branch
BranchTrueFalseTotal
if defined $wday 0 0 0
585 0 ▶ $struct{yday} = $yday if defined $yday;
Branch: 1 branch
BranchTrueFalseTotal
if defined $yday 0 0 0
586 0 ▶ $struct{year} = $year if defined $year;
Branch: 1 branch
BranchTrueFalseTotal
if defined $year 0 0 0
587 0 ▶ $struct{epoch} = $epoch if defined $epoch;
Branch: 1 branch
BranchTrueFalseTotal
if defined $epoch 0 0 0
588 0 ▶ $struct{tz} = $tz if defined $tz;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tz 0 0 0
589 0 ▶ $struct{offset} = $offset_n if defined $offset_n;
Branch: 1 branch
BranchTrueFalseTotal
if defined $offset_n 0 0 0
590  
591 0 return %struct;
592 9 }
593  
594 0 ▶fun _offset_to_minutes ($offset) {
Subroutine _offset_to_minutes: not called CC=2 SCAR=17.9
595 0 my ($sign, $hours, $minutes) = $offset =~ m/^([+-])([0-9][0-9]):?([0-9][0-9])?$/;
596 0 ▶ return $sign eq '+' ? ($hours * 60 + $minutes) : -($hours * 60 + $minutes);
Branch: 1 branch
BranchTrueFalseTotal
$sign eq '+' ? : 0 0 0
597 9 }
598  
599 0 ▶fun _get_index ($needle, @haystack) {
Subroutine _get_index: not called CC=5 SCAR=34.0
600 0 ▶ if (not @haystack and $needle eq '') { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if (not @haystack and $needle eq "") 0 0 0
Condition0%0/3
not @haystack and $needle eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
not @haystack and $needle eq ""
not @haystack $needle eq ""
Truth table0%0/3
not(A) and B
A= not @haystackB= $needle eq ""
ABresult
0X0
100
111
601  
602 0 foreach my $i (0 .. $#haystack) {
603 0 ▶ return $i if $haystack[$i] eq $needle;
Branch: 1 branch
BranchTrueFalseTotal
if $haystack[$i] eq $needle 0 0 0
604 }
605 0 croak "Could not find $needle in the list.";
606 9 }
607  
608 0 ▶fun _get_eras ($type, $locale) {
Subroutine _get_eras: not called CC=2 SCAR=17.9
609 0 my @eras = @{ get_locale(era => $locale) };
610 0 ▶ my @ret = map { my @fields = split /:/; $type eq 'period' ? $fields[4] : $fields[5] } @eras;
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'period' ? : 0 0 0
611  
612 0 return @ret;
613 9 }
614  
615 9 1;
616  
617 __END__
« C/Util.pm ↑ Summary D.pm »