lib/Date/Manip/Date.pm

filter: Statementstmt 86.5% 2303 / 2661 Branchbran 77.1% 1168 / 1514 Conditioncond 76.3% 536 / 702 MC/DCmcdc 56.3% 208 / 369 Subroutinesub 98.8% 88 / 89 Podpod 100% 24 / 24 totaltotal 80.7% 4327 / 5359 CC 1010 SCAR 50.0
CC
1010
Cov
82%
_format_regexp
1221.7
parse_format
215.2
set
173.1
CRAP 148.1
« lib/Date/Manip/TZdata.pm ↑ Summary lib/Date/Manip/Recur.pm »
1 package Date::Manip::Date;
2 # Copyright (c) 1995-2026 Sullivan Beck. All rights reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the same terms as Perl itself.
5  
6 ########################################################################
7 # Any routine that starts with an underscore (_) is NOT intended for
8 # public use. They are for internal use in the the Date::Manip
9 # modules and are subject to change without warning or notice.
10 #
11 # ABSOLUTELY NO USER SUPPORT IS OFFERED FOR THESE ROUTINES!
12 ########################################################################
13  
14 170 ▶use Date::Manip::Obj;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 170 @ISA = ('Date::Manip::Obj');
16  
17 170 require 5.010000;
18 170 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 170 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 170 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 170 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 170 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 170 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 170 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 #use re 'debug';
26  
27 170 ▶use Date::Manip::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 170 ▶use Date::Manip::TZ;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 170 our $VERSION;
31 170 $VERSION='7.00';
32 170 ▶END { undef $VERSION; }
Subroutine END: called CC=1 SCAR=0.0
33  
34 ########################################################################
35 # BASE METHODS
36 ########################################################################
37  
38 1 ▶sub is_date {
Subroutine is_date: called CC=1 SCAR=0.0
Pod documented
39 1 return 1;
40 }
41  
42 # Call this every time a new date is put in to make sure everything is
43 # correctly initialized.
44 #
45 24339 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
46 24339 my($self) = @_;
47  
48 24339 $$self{'err'} = '';
49  
50 24339 $$self{'data'} =
51 {
52 'set' => 0, # 1 if the date has been set
53 # 2 if the date is in the process of being set
54  
55 # The date as input
56 'in' => '', # the string that was parsed (if any)
57 'zin' => '', # the timezone that was parsed (if any)
58  
59 # The date in the parsed timezone
60 'date' => [], # the parsed date split
61 'def' => [0,0,0,0,0,0],
62 # 1 for each field that came from
63 # defaults rather than parsed
64 # '' for an implied field
65 'tz' => '', # the timezone of the date
66 'isdst' => '', # 1 if the date is in DST.
67 'offset' => [], # The offset from GMT
68 'abb' => '', # The timezone abbreviation.
69 'f' => {}, # fields used in printing a date
70  
71 # The date in GMT
72 'gmt' => [], # the date converted to GMT
73  
74 # The date in local timezone
75 'loc' => [], # the date converted to local timezone
76 };
77 24339 return;
78 }
79  
80 11 ▶sub _init_args {
Subroutine _init_args: called CC=1 SCAR=0.0
81 11 my($self) = @_;
82  
83 11 my @args = @{ $$self{'args'} };
84 11 $self->parse(@args);
85 11 return;
86 }
87  
88 0 ▶sub input {
Subroutine input: not called CC=1 SCAR=6.9
Pod documented
89 0 my($self) = @_;
90 0 return $$self{'data'}{'in'};
91 }
92  
93 ########################################################################
94 # DATE PARSING
95 ########################################################################
96  
97 4106 ▶sub parse {
Subroutine parse: called CC=43 SCAR=37.9
Pod documented
98 4106 my($self,$instring,@opts) = @_;
99 4106 $self->_init();
100 4106 my $noupdate = 0;
101  
102 4106 ▶ if (! $instring) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($instring) 0 4106 4106
103 0 $$self{'err'} = '[parse] Empty date string';
104 0 return 1;
105 }
106  
107 4106 my %opts = map { $_,1 } @opts;
108  
109 4106 my $dmt = $$self{'tz'};
110 4106 my $dmb = $$dmt{'base'};
111 4106 delete $$self{'data'}{'default_time'};
112  
113 4106 my($done,$y,$m,$d,$h,$mn,$s,$tzstring,$zone,$abb,$off,$dow,$got_time,
114 $default_time,$firsterr);
115  
116 ENCODING:
117 4106 foreach my $string ($dmb->_encoding($instring)) {
118 4239 $got_time = 0;
119 4239 $default_time = 0;
120  
121 # Put parse in a simple loop for an easy exit.
122 PARSE:
123 {
124 4239 my(@tmp,$tmp);
125 4239 $$self{'err'} = '';
126  
127 ###################
128 # Handle some special language-specific rules
129  
130 # Some languages add a trailing period in some places. For example,
131 # the default German date format (running the system date command)
132 # produces: Mo 3. Jan 11:00:00 EST 2022
133 # The '3.' needs to have the period stripped.
134  
135 4239 ▶ if ($self->_parse_rule('remove_trailing_period')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_parse_rule("remove_trailing_period")) 8 4231 4239
136 8 $string =~ s/\.\s/ /g;
137 8 $string =~ s/\.$//;
138 }
139  
140 # Some languages add parenthese. For example, the default date
141 # output in russian in some cases puts the timezone in parentheses.
142  
143 4239 ▶ if ($self->_parse_rule('remove_parens')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_parse_rule("remove_parens")) 42 4197 4239
144 42 $string =~ s/\(//g;
145 42 $string =~ s/\)//;
146 }
147  
148 4239 my $words = $self->_parse_rule('strip_word');
149 4239 ▶ if ($words) {
Branch: 1 branch
BranchTrueFalseTotal
if ($words) 42 4197 4239
150 42 foreach my $w (@$words) {
151 42 $string =~ s/(?:^|\s)\Q$w\E(?:\s|$)/ /;
152 }
153 }
154  
155 ###################
156  
157 # Check the standard date format
158  
159 4239 $tmp = $dmb->split('date',$string);
160 4239 ▶ if (defined($tmp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp) 1922 2317 4239
161 1922 ($y,$m,$d,$h,$mn,$s) = @$tmp;
162 1922 $got_time = 1;
163 1922 last PARSE;
164 }
165  
166 # Parse ISO 8601 dates now (which may have a timezone).
167  
168 2317 ▶ if (! exists $opts{'noiso8601'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts{"noiso8601"}) 2312 5 2317
169 2312 ($done,@tmp) = $self->_parse_datetime_iso8601($string,\$noupdate);
170 2312 ▶ if ($done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($done) 314 1998 2312
171 314 ($y,$m,$d,$h,$mn,$s,$tzstring,$zone,$abb,$off) = @tmp;
172 314 $got_time = 1;
173 314 last PARSE;
174 }
175 }
176  
177 # There's lots of ways that commas may be included. Remove
178 # them (unless it's preceded and followed by a digit in
179 # which case it's probably a fractional separator).
180  
181 2003 $string =~ s/(?<!\d),/ /g;
182 2003 $string =~ s/,(?!\d)/ /g;
183  
184 # Some special full date/time formats ('now', 'epoch')
185  
186 2003 ▶ if (! exists $opts{'nospecial'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts{"nospecial"}) 2003 0 2003
187 2003 ($done,@tmp) = $self->_parse_datetime_other($string,\$noupdate);
188 2003 ▶ if ($done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($done) 24 1979 2003
189 24 ($y,$m,$d,$h,$mn,$s,$tzstring,$zone,$abb,$off) = @tmp;
190 24 $got_time = 1;
191 24 last PARSE;
192 }
193 }
194  
195 # Parse (and remove) the time (and an immediately following timezone).
196  
197 1979 ($got_time,@tmp) = $self->_parse_time('parse',$string,\$noupdate,%opts);
198 1979 ▶ if ($got_time) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got_time) 1108 871 1979
199 1108 ($string,$h,$mn,$s,$tzstring,$zone,$abb,$off) = @tmp;
200 }
201  
202 1979 ▶ if (! $string) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($string) 10 1969 1979
203 10 ($y,$m,$d) = $self->_def_date($y,$m,$d,\$noupdate);
204 10 last;
205 }
206  
207 # Parse (and remove) the day of week. Also, handle the simple DoW
208 # formats.
209  
210 1969 ▶ if (! exists $opts{'nodow'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts{"nodow"}) 1969 0 1969
211 1969 ($done,@tmp) = $self->_parse_dow($string,\$noupdate);
212 1969 ▶ if (@tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmp) 597 1372 1969
213 597 ▶ if ($done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($done) { } 12 585 597
214 12 ($y,$m,$d) = @tmp;
215 12 $default_time = 1;
216 12 last PARSE;
217 } else {
218 585 ($string,$dow) = @tmp;
219 }
220 }
221 }
222 1957 ▶ $dow = 0 if (! $dow);
Branch: 1 branch
BranchTrueFalseTotal
unless $dow 1372 585 1957
223  
224 # At this point, the string might contain the following dates:
225 #
226 # OTHER
227 # OTHER ZONE / ZONE OTHER
228 # DELTA
229 # DELTA ZONE / ZONE DELTA
230 # HOLIDAY
231 # HOLIDAY ZONE / ZONE HOLIDAY
232 #
233 # ZONE is only allowed if it wasn't parsed with the time
234  
235 # Unfortunately, there are some conflicts between zones and
236 # some other formats, so try parsing the entire string as a date.
237  
238 1957 (@tmp) = $self->_parse_date($string,$dow,\$noupdate,%opts);
239 1957 ▶ if (@tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmp) 1663 294 1957
240 1663 my $dow2;
241 1663 ($y,$m,$d,$dow2) = @tmp;
242 1663 ▶ if ($dow2 && $dow && $dow != $dow2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dow2 and $dow and $dow != $dow2) 0 1663 1663
Condition66%4/6
$dow2 and $dow and $dow != $dow2
!ll&&!rl&&r
11255380
$dow2 and $dow
!ll&&!rl&&r
11250538
MC/DC0%0/3
$dow2 and $dow and $dow != $dow2
$dow2 $dow $dow != $dow2
Truth table50%2/4
A and B and C
A= $dow2B= $dowC= $dow != $dow2
ABCresult
0XX0
10X0
1100
1111
243 0 $$self{'err'} = '[parse] Day of week invalid';
244 0 last PARSE;
245 }
246 1663 ▶ $dow = $dow2 if ($dow2);
Branch: 1 branch
BranchTrueFalseTotal
if $dow2 538 1125 1663
247 1663 $default_time = 1;
248 1663 last PARSE;
249 }
250  
251 # Parse any timezone
252  
253 294 ▶ if (! $tzstring) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tzstring) 281 13 294
254 281 ($string,@tmp) = $self->_parse_tz($string,\$noupdate);
255 281 ▶ ($tzstring,$zone,$abb,$off) = @tmp if (@tmp);
Branch: 1 branch
BranchTrueFalseTotal
if @tmp 9 272 281
256 281 ▶ last PARSE if (! $string);
Branch: 1 branch
BranchTrueFalseTotal
unless $string 0 281 281
257 }
258  
259 # Try the remainder of the string as a date.
260  
261 294 ▶ if ($tzstring) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tzstring) 22 272 294
262 22 (@tmp) = $self->_parse_date($string,$dow,\$noupdate,%opts);
263 22 ▶ if (@tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmp) 1 21 22
264 1 ($y,$m,$d,$dow) = @tmp;
265 1 $default_time = 1;
266 1 last PARSE;
267 }
268 }
269  
270 # Parse deltas
271 #
272 # Occasionally, a delta is entered for a date (which is
273 # interpreted as the date relative to now). There can be some
274 # confusion between a date and a delta, but the most
275 # important conflicts are the ISO 8601 dates (many of which
276 # could be interpreted as a delta), but those have already
277 # been taken care of.
278 #
279 # We may have already gotten the time:
280 # 3 days ago at midnight UTC
281 # (we already stripped off the 'at midnight UTC' above).
282 #
283 # We also need to handle the sitution of a delta and a timezone.
284 # in 2 hours EST
285 # in 2 days EST
286 # but only if no time was entered.
287  
288 293 ▶ if (! exists $opts{'nodelta'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts{"nodelta"}) 185 108 293
289  
290 185 ($done,@tmp) =
291 $self->_parse_delta($string,$dow,$got_time,$h,$mn,$s,\$noupdate);
292 185 ▶ if (@tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmp) 30 155 185
293 30 ($y,$m,$d,$h,$mn,$s) = @tmp;
294 30 $got_time = 1;
295 30 $dow = '';
296 }
297 185 ▶ last PARSE if ($done);
Branch: 1 branch
BranchTrueFalseTotal
if $done 36 149 185
298  
299 # We'll also check the original string to see if it's a valid
300 # delta since some deltas may have interpreted part of it as
301 # a time or timezone.
302  
303 149 ($done,@tmp) =
304 $self->_parse_delta($instring,$dow,$got_time,$h,$mn,$s,\$noupdate);
305 149 ▶ if (@tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmp) 0 149 149
306 0 ($y,$m,$d,$h,$mn,$s) = @tmp;
307 0 $got_time = 1;
308 0 $dow = '';
309 0 ($tzstring,$zone,$abb,$off) = ();
310 }
311 149 ▶ last PARSE if ($done);
Branch: 1 branch
BranchTrueFalseTotal
if $done 0 149 149
312 }
313  
314 # Parse holidays
315  
316 257 ▶ unless (exists $opts{'noholidays'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts{"noholidays"}) 257 0 257
317 257 ($done,@tmp) =
318 $self->_parse_holidays($string,\$noupdate);
319 257 ▶ if (@tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmp) 9 248 257
320 9 ($y,$m,$d) = @tmp;
321 }
322 257 ▶ last PARSE if ($done);
Branch: 1 branch
BranchTrueFalseTotal
if $done 9 248 257
323 }
324  
325 248 $$self{'err'} = '[parse] Invalid date string';
326 248 last PARSE;
327 }
328  
329 # We got an error parsing this encoding of the string. It could
330 # be that it is a genuine error, or it may be that we simply
331 # need to try a different encoding. If ALL encodings fail, we'll
332 # return the error from the first one.
333  
334 4239 ▶ if ($$self{'err'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"}) 254 3985 4239
335 254 ▶ if (! $firsterr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($firsterr) 129 125 254
336 129 $firsterr = $$self{'err'};
337 }
338 254 next ENCODING;
339 }
340  
341 # If we didn't get an error, this is the string to use.
342  
343 3985 last ENCODING;
344 }
345  
346 4106 ▶ if ($$self{'err'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"}) 121 3985 4106
347 121 $$self{'err'} = $firsterr;
348 121 return 1;
349 }
350  
351 # Make sure that a time is set
352  
353 3985 ▶ if (! $got_time) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($got_time) 611 3374 3985
354 611 ▶ if ($default_time) {
Branch: 1 branch
BranchTrueFalseTotal
if ($default_time) { } 606 5 611
355 606 ▶ if (exists $$self{'data'}{'default_time'}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'data'}{'default_time'}) { } 8 598 606
elsif ($dmb->_config('defaulttime') eq 'midnight') { } 582 16 598
356 8 ($h,$mn,$s) = @{ $$self{'data'}{'default_time'} };
357 8 delete $$self{'data'}{'default_time'};
358 } elsif ($dmb->_config('defaulttime') eq 'midnight') {
359 582 ($h,$mn,$s) = (0,0,0);
360 } else {
361 16 ($h,$mn,$s) = $dmt->_now('time',$noupdate);
362 16 $noupdate = 1;
363 }
364 606 $got_time = 1;
365 } else {
366 5 ($h,$mn,$s) = $self->_def_time(undef,undef,undef,\$noupdate);
367 }
368 }
369  
370 3985 $$self{'data'}{'set'} = 2;
371 3985 return $self->_parse_check('parse',$instring,
372 $y,$m,$d,$h,$mn,$s,$dow,$tzstring,$zone,$abb,$off);
373 }
374  
375 30 ▶sub parse_time {
Subroutine parse_time: called CC=5 SCAR=17.5
Pod documented
376 30 my($self,$string,@opts) = @_;
377 0 my %opts = map { $_,1 } @opts;
378 30 my $noupdate = 0;
379  
380 30 ▶ if (! $string) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($string) 0 30 30
381 0 $$self{'err'} = '[parse_time] Empty time string';
382 0 return 1;
383 }
384  
385 30 my($y,$m,$d,$h,$mn,$s);
386  
387 30 ▶ if ($$self{'err'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"}) 0 30 30
388 0 $self->_init();
389 }
390 30 ▶ if ($$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'data'}{'set'}) { } 0 30 30
391 0 ($y,$m,$d,$h,$mn,$s) = @{ $$self{'data'}{'date'} };
392 } else {
393 30 my $dmt = $$self{'tz'};
394 30 ($y,$m,$d,$h,$mn,$s) = $dmt->_now('now',$noupdate);
395 30 $noupdate = 1;
396 }
397 30 my($tzstring,$zone,$abb,$off);
398  
399 30 ($h,$mn,$s,$tzstring,$zone,$abb,$off) =
400 $self->_parse_time('parse_time',$string,\$noupdate,%opts);
401  
402 30 ▶ return 1 if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 5 25 30
403  
404 25 $$self{'data'}{'set'} = 2;
405 25 return $self->_parse_check('parse_time','',
406 $y,$m,$d,$h,$mn,$s,'',$tzstring,$zone,$abb,$off);
407 }
408  
409 1012 ▶sub parse_date {
Subroutine parse_date: called CC=8 SCAR=21.0
Pod documented
410 1012 my($self,$string,@opts) = @_;
411 0 my %opts = map { $_,1 } @opts;
412 1012 my $noupdate = 0;
413  
414 1012 ▶ if (! $string) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($string) 0 1012 1012
415 0 $$self{'err'} = '[parse_date] Empty date string';
416 0 return 1;
417 }
418  
419 1012 my $dmt = $$self{'tz'};
420 1012 my $dmb = $$dmt{'base'};
421 1012 my($y,$m,$d,$h,$mn,$s);
422  
423 1012 ▶ if ($$self{'err'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"}) 2 1010 1012
424 2 $self->_init();
425 }
426 1012 ▶ if ($$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'data'}{'set'}) { } 7 1005 1012
427 7 ($y,$m,$d,$h,$mn,$s) = @{ $$self{'data'}{'date'} };
428 } else {
429 1005 ($h,$mn,$s) = (0,0,0);
430 }
431  
432 # Put parse in a simple loop for an easy exit.
433 1012 my($done,@tmp,$dow);
434 PARSE:
435 {
436  
437 # Parse ISO 8601 dates now
438  
439 1012 ▶ unless (exists $opts{'noiso8601'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts{"noiso8601"}) 1012 0 1012
440 1012 ($done,@tmp) = $self->_parse_date_iso8601($string,\$noupdate);
441 1012 ▶ if ($done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($done) 70 942 1012
442 70 ($y,$m,$d) = @tmp;
443 70 last PARSE;
444 }
445 }
446  
447 942 (@tmp) = $self->_parse_date($string,undef,\$noupdate,%opts);
448 942 ▶ if (@tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmp) 818 124 942
449 818 ($y,$m,$d,$dow) = @tmp;
450 818 last PARSE;
451 }
452  
453 124 $$self{'err'} = '[parse_date] Invalid date string';
454 124 return 1;
455 }
456  
457 888 ▶ return 1 if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 0 888 888
458  
459 888 $y = $dmt->_fix_year($y);
460  
461 888 $$self{'data'}{'set'} = 2;
462 888 return $self->_parse_check('parse_date','',$y,$m,$d,$h,$mn,$s,$dow);
463 }
464  
465 2921 ▶sub _parse_date {
Subroutine _parse_date: called CC=15 SCAR=27.1
466 2921 my($self,$string,$dow,$noupdate,%opts) = @_;
467  
468 # There's lots of ways that commas may be included. Remove
469 # them.
470 #
471 # Also remove some words we should ignore.
472  
473 2921 $string =~ s/,/ /g;
474  
475 2921 my $dmt = $$self{'tz'};
476 2921 my $dmb = $$dmt{'base'};
477 my $ign = (exists $$dmb{'data'}{'rx'}{'other'}{'ignore'} ?
478 2921 ▶ $$dmb{'data'}{'rx'}{'other'}{'ignore'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $dmb->{'data'}{'rx'}{'other'}{'ignore'} ? : 2848 73 2921
479 $self->_other_rx('ignore'));
480 2921 $string =~ s/$ign/ /g;
481 2921 my $of = $+{'of'};
482  
483 2921 $string =~ s/\s*$//;
484 2921 ▶ return () if (! $string);
Branch: 1 branch
BranchTrueFalseTotal
unless $string 0 2921 2921
485  
486 2921 my($done,$y,$m,$d,@tmp);
487  
488 # Put parse in a simple loop for an easy exit.
489 PARSE:
490 {
491  
492 # Parse (and remove) the day of week. Also, handle the simple DoW
493 # formats.
494  
495 2921 ▶ unless (exists $opts{'nodow'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts{"nodow"}) 2921 0 2921
496 2921 ▶ if (! defined($dow)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dow) 942 1979 2921
497 942 ($done,@tmp) = $self->_parse_dow($string,$noupdate);
498 942 ▶ if (@tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmp) 664 278 942
499 664 ▶ if ($done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($done) { } 6 658 664
500 6 ($y,$m,$d) = @tmp;
501 6 last PARSE;
502 } else {
503 658 ($string,$dow) = @tmp;
504 }
505 }
506 936 ▶ $dow = 0 if (! $dow);
Branch: 1 branch
BranchTrueFalseTotal
unless $dow 278 658 936
507 }
508 }
509  
510 # Parse common dates
511  
512 2915 ▶ unless (exists $opts{'nocommon'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts{"nocommon"}) 2915 0 2915
513 2915 (@tmp) = $self->_parse_date_common($string,$noupdate);
514 2915 ▶ if (@tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmp) 1586 1329 2915
515 1586 ($y,$m,$d) = @tmp;
516 1586 last PARSE;
517 }
518 }
519  
520 # Parse less common dates
521  
522 1329 ▶ unless (exists $opts{'noother'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts{"noother"}) 1329 0 1329
523 1329 (@tmp) = $self->_parse_date_other($string,$dow,$of,$noupdate);
524 1329 ▶ if (@tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmp) 874 455 1329
525 874 ($y,$m,$d,$dow) = @tmp;
526 874 last PARSE;
527 }
528 }
529  
530 # Parse truncated dates
531  
532 455 ▶ if (! $dow && ! $of) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dow or $of) 420 35 455
Condition100%3/3
$dow or $of
l!l&&r!l&&!r
2510420
MC/DC100%2/2
$dow or $of
$dow $of
Truth table100%3/3
A or B
A= $dowB= $of
ABresult
1X1
011
000
533 420 (@tmp) = $self->_parse_date_truncated($string,$noupdate);
534 420 ▶ if (@tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmp) 16 404 420
535 16 ($y,$m,$d,$dow) = @tmp;
536 16 last PARSE;
537 }
538 }
539  
540 439 return ();
541 }
542  
543 2482 return($y,$m,$d,$dow);
544 }
545  
546 7 ▶sub parse_format {
Subroutine parse_format: called CC=33 SCAR=53.7
Pod documented
547 7 my($self,$format,$string) = @_;
548 7 $self->_init();
549 7 my $noupdate = 0;
550  
551 7 ▶ if (! $string) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($string) 0 7 7
552 0 $$self{'err'} = '[parse_format] Empty date string';
553 0 return 1;
554 }
555  
556 7 my $dmt = $$self{'tz'};
557 7 my $dmb = $$dmt{'base'};
558  
559 7 my($err,$re) = $self->_format_regexp($format);
560 7 ▶ return $err if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 7 7
561 7 ▶ return 1 if ($string !~ $re);
Branch: 1 branch
BranchTrueFalseTotal
unless $string =~ /$re/ 0 7 7
562  
563 my($y,$m,$d,$h,$mn,$s,
564 $mon_name,$mon_abb,$dow_name,$dow_abb,$dow_char,$dow_num,
565 $doy,$nth,$ampm,$epochs,$epocho,
566 $tzstring,$off,$abb,$zone,
567 $g,$w,$l,$u) =
568 7 @+{qw(y m d h mn s
569 mon_name mon_abb dow_name dow_abb dow_char dow_num doy
570 nth ampm epochs epocho tzstring off abb zone g w l u)};
571  
572 7 while (1) {
573 # Get y/m/d/h/mn/s from:
574 # $epochs,$epocho
575  
576 7 ▶ if (defined($epochs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $epochs) 0 7 7
577 0 ($y,$m,$d,$h,$mn,$s) = @{ $dmb->secs_since_1970($epochs) };
578 0 my $z;
579 0 ▶ if ($zone) {
Branch: 2 branches
BranchTrueFalseTotal
if ($zone) { } 0 0 0
elsif ($abb or $off) { } 0 0 0
580 0 $z = $dmt->_zone($zone);
581 0 ▶ return 'Invalid zone' if (! $z);
Branch: 1 branch
BranchTrueFalseTotal
unless $z 0 0 0
582 ▶ } elsif ($abb || $off) {
Condition0%0/3
$abb or $off
l!l&&r!l&&!r
000
MC/DC0%0/2
$abb or $off
$abb $off
Truth table0%0/3
A or B
A= $abbB= $off
ABresult
1X1
011
000
583 0 my $offset = $dmb->_delta_convert('offset',$off);
584 0 $z = $dmt->__zone([],$offset,'',$abb,'');
585 0 ▶ if (! $z) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($z) 0 0 0
586 0 $z = $dmt->__zone([],$offset,$abb,'','');
587 }
588 0 ▶ return 'Invalid zone' if (! $z);
Branch: 1 branch
BranchTrueFalseTotal
unless $z 0 0 0
589 } else {
590 0 $z = $dmt->_now('tz',$noupdate);
591 0 $noupdate = 1;
592 }
593 0 my($err,$date) = $dmt->convert_from_gmt([$y,$m,$d,$h,$mn,$s],$z);
594 0 ($y,$m,$d,$h,$mn,$s) = @$date;
595 0 last;
596 }
597  
598 7 ▶ if (defined($epocho)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $epocho) 0 7 7
599 0 ($y,$m,$d,$h,$mn,$s) = @{ $dmb->secs_since_1970($epocho) };
600 0 last;
601 }
602  
603 # Get y/m/d from:
604 # $y,$m,$d,
605 # $mon_name,$mon_abb
606 # $doy,$nth
607 # $g/$w,$l/$u
608  
609 7 ▶ if ($mon_name) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mon_name) { } 0 7 7
elsif ($mon_abb) { } 2 5 7
610 0 $m = $$dmb{'data'}{'wordmatch'}{'month_name'}{lc($mon_name)};
611 } elsif ($mon_abb) {
612 2 $m = $$dmb{'data'}{'wordmatch'}{'month_abb'}{lc($mon_abb)};
613 }
614  
615 7 ▶ if ($nth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nth) 0 7 7
616 0 $d = $$dmb{'data'}{'wordmatch'}{'nth'}{lc($nth)};
617 }
618  
619 7 ▶ if ($doy) {
Branch: 4 branches
BranchTrueFalseTotal
if ($doy) { } 0 7 7
elsif ($g) { } 0 7 7
elsif ($l) { } 0 7 7
elsif ($m) { } 5 2 7
620 0 ▶ $y = $dmt->_now('y',$noupdate) if (! $y);
Branch: 1 branch
BranchTrueFalseTotal
unless $y 0 0 0
621 0 $noupdate = 1;
622 0 ($y,$m,$d) = @{ $dmb->day_of_year($y,$doy) };
623  
624 } elsif ($g) {
625 0 ▶ $y = $dmt->_now('y',$noupdate) if (! $y);
Branch: 1 branch
BranchTrueFalseTotal
unless $y 0 0 0
626 0 $noupdate = 1;
627  
628 0 my $currfirst = $dmb->_config('firstday');
629 0 $dmb->config('firstday',1);
630 0 ($y,$m,$d) = @{ $dmb->week_of_year($g,$w) };
631 0 $dmb->config('firstday',$currfirst);
632  
633 } elsif ($l) {
634 0 ▶ $y = $dmt->_now('y',$noupdate) if (! $y);
Branch: 1 branch
BranchTrueFalseTotal
unless $y 0 0 0
635 0 $noupdate = 1;
636  
637 0 my $currfirst = $dmb->_config('firstday');
638 0 $dmb->config('firstday',7);
639 0 ($y,$m,$d) = @{ $dmb->week_of_year($l,$u) };
640 0 $dmb->config('firstday',$currfirst);
641  
642 } elsif ($m) {
643 5 ($y,$m,$d) = $self->_def_date($y,$m,$d,\$noupdate);
644 }
645  
646 # Get h/mn/s from:
647 # $h,$mn,$s,$ampm
648  
649 7 ▶ if (defined($h)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h) 4 3 7
650 4 ($h,$mn,$s) = $self->_def_time($h,$mn,$s,\$noupdate);
651 }
652  
653 7 ▶ if ($ampm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ampm) 2 5 7
654 2 ▶ if ($$dmb{'data'}{'wordmatch'}{'ampm'}{lc($ampm)} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dmb->{'data'}{'wordmatch'}{'ampm'}{lc $ampm} == 2) { } 0 2 2
655 # pm times
656 0 ▶ $h+=12 unless ($h==12);
Branch: 1 branch
BranchTrueFalseTotal
unless $h == 12 0 0 0
657 } else {
658 # am times
659 2 ▶ $h=0 if ($h==12);
Branch: 1 branch
BranchTrueFalseTotal
if $h == 12 2 0 2
660 }
661 }
662  
663 # Get dow from:
664 # $dow_name,$dow_abb,$dow_char,$dow_num
665  
666 7 ▶ if ($dow_name) {
Branch: 3 branches
BranchTrueFalseTotal
if ($dow_name) { } 0 7 7
elsif ($dow_abb) { } 0 7 7
elsif ($dow_char) { } 0 7 7
667 0 $dow_num = $$dmb{'data'}{'wordmatch'}{'day_name'}{lc($dow_name)};
668 } elsif ($dow_abb) {
669 0 $dow_num = $$dmb{'data'}{'wordmatch'}{'day_abb'}{lc($dow_abb)};
670 } elsif ($dow_char) {
671 0 $dow_num = $$dmb{'data'}{'wordmatch'}{'day_char'}{lc($dow_char)};
672 }
673  
674 7 last;
675 }
676  
677 7 ▶ if (! $m) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($m) 2 5 7
678 2 ($y,$m,$d) = $dmt->_now('now',$noupdate);
679 2 $noupdate = 1;
680 }
681 7 ▶ if (! defined($h)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $h) 3 4 7
682 3 ($h,$mn,$s) = (0,0,0);
683 }
684  
685 7 $$self{'data'}{'set'} = 2;
686 7 $err = $self->_parse_check('parse_format',$string,
687 $y,$m,$d,$h,$mn,$s,$dow_num,
688 $tzstring,$zone,$abb,$off);
689  
690 7 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 1 6 7
691 1 my %tmp = %{ dclone(\%+) };
692 1 return ($err,%tmp);
693 }
694 6 return $err;
695 }
696  
697 170 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
698 170 my %y_form = map { $_,1 } qw( Y y s o G L );
699 170 my %m_form = map { $_,1 } qw( m f b h B j s o W U );
700 170 my %d_form = map { $_,1 } qw( j d e E s o W U );
701 170 my %h_form = map { $_,1 } qw( H I k i s o );
702 170 my %mn_form = map { $_,1 } qw( M s o );
703 170 my %s_form = map { $_,1 } qw( S s o );
704  
705 170 my %dow_form = map { $_,1 } qw( v a A w );
706 170 my %am_form = map { $_,1 } qw( p s o );
707 170 my %z_form = map { $_,1 } qw( Z z N );
708 170 my %mon_form = map { $_,1 } qw( b h B );
709 170 my %day_form = map { $_,1 } qw( v a A );
710  
711 7 ▶ sub _format_regexp {
Subroutine _format_regexp: called CC=89 SCAR=71.1
712 7 my($self,$format) = @_;
713 7 my $dmt = $$self{'tz'};
714 7 my $dmb = $$dmt{'base'};
715  
716 7 ▶ if (exists $$dmb{'data'}{'format'}{$format}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dmb->{"data"}{"format"}{$format}) 0 7 7
717 0 return @{ $$dmb{'data'}{'format'}{$format} };
718 }
719  
720 7 my $re;
721 my $err;
722 7 my($y,$m,$d,$h,$mn,$s) = (0,0,0,0,0,0);
723 7 my($dow,$ampm,$zone,$G,$W,$L,$U) = (0,0,0,0,0,0,0);
724  
725 7 ▶ while ($format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format) 65 7 72
726 65 ▶ last if ($format eq '%');
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "%" 0 65 65
727  
728 65 ▶ if ($format =~ s/^([^%]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ s/^([^%]+)//) 30 35 65
729 30 $re .= $1;
730 30 next;
731 }
732  
733 35 $format =~ s/^%(.)//;
734 35 my $f = $1;
735  
736 35 ▶ if (exists $y_form{$f}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $y_form{$f}) 5 30 35
737 5 ▶ if ($y) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y) 0 5 5
738 0 $err = 'Year specified multiple times';
739 0 last;
740 }
741 5 $y = 1;
742 }
743  
744 35 ▶ if (exists $m_form{$f}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $m_form{$f}) 5 30 35
745 5 ▶ if ($m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m) 0 5 5
746 0 $err = 'Month specified multiple times';
747 0 last;
748 }
749 5 $m = 1;
750 }
751  
752 35 ▶ if (exists $d_form{$f}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $d_form{$f}) 5 30 35
753 5 ▶ if ($d) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d) 0 5 5
754 0 $err = 'Day specified multiple times';
755 0 last;
756 }
757 5 $d = 1;
758 }
759  
760 35 ▶ if (exists $h_form{$f}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $h_form{$f}) 4 31 35
761 4 ▶ if ($h) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h) 0 4 4
762 0 $err = 'Hour specified multiple times';
763 0 last;
764 }
765 4 $h = 1;
766 }
767  
768 35 ▶ if (exists $mn_form{$f}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $mn_form{$f}) 4 31 35
769 4 ▶ if ($mn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mn) 0 4 4
770 0 $err = 'Minutes specified multiple times';
771 0 last;
772 }
773 4 $mn = 1;
774 }
775  
776 35 ▶ if (exists $s_form{$f}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $s_form{$f}) 4 31 35
777 4 ▶ if ($s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s) 0 4 4
778 0 $err = 'Seconds specified multiple times';
779 0 last;
780 }
781 4 $s = 1;
782 }
783  
784 35 ▶ if (exists $dow_form{$f}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dow_form{$f}) 0 35 35
785 0 ▶ if ($dow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dow) 0 0 0
786 0 $err = 'Day-of-week specified multiple times';
787 0 last;
788 }
789 0 $dow = 1;
790 }
791  
792 35 ▶ if (exists $am_form{$f}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $am_form{$f}) 2 33 35
793 2 ▶ if ($ampm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ampm) 0 2 2
794 0 $err = 'AM/PM specified multiple times';
795 0 last;
796 }
797 2 $ampm = 1;
798 }
799  
800 35 ▶ if (exists $z_form{$f}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $z_form{$f}) 2 33 35
801 2 ▶ if ($zone) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone) 0 2 2
802 0 $err = 'Zone specified multiple times';
803 0 last;
804 }
805 2 $zone = 1;
806 }
807  
808 35 ▶ if ($f eq 'G') {
Branch: 4 branches
BranchTrueFalseTotal
if ($f eq 'G') { } 0 35 35
elsif ($f eq 'W') { } 0 35 35
elsif ($f eq 'L') { } 0 35 35
elsif ($f eq 'U') { } 0 35 35
809 0 ▶ if ($G) {
Branch: 1 branch
BranchTrueFalseTotal
if ($G) 0 0 0
810 0 $err = 'G specified multiple times';
811 0 last;
812 }
813 0 $G = 1;
814  
815 } elsif ($f eq 'W') {
816 0 ▶ if ($W) {
Branch: 1 branch
BranchTrueFalseTotal
if ($W) 0 0 0
817 0 $err = 'W specified multiple times';
818 0 last;
819 }
820 0 $W = 1;
821  
822 } elsif ($f eq 'L') {
823 0 ▶ if ($L) {
Branch: 1 branch
BranchTrueFalseTotal
if ($L) 0 0 0
824 0 $err = 'L specified multiple times';
825 0 last;
826 }
827 0 $L = 1;
828  
829 } elsif ($f eq 'U') {
830 0 ▶ if ($U) {
Branch: 1 branch
BranchTrueFalseTotal
if ($U) 0 0 0
831 0 $err = 'U specified multiple times';
832 0 last;
833 }
834 0 $U = 1;
835 }
836  
837 ###
838  
839 35 ▶ if ($f eq 'Y') {
Branch: 42 branches
BranchTrueFalseTotal
if ($f eq 'Y') { } 5 30 35
elsif ($f eq 'y') { } 0 30 30
elsif ($f eq 'm') { } 3 27 30
elsif ($f eq 'f') { } 0 27 27
elsif (exists $mon_form{$f}) { } 2 25 27
elsif ($f eq 'j') { } 0 25 25
elsif ($f eq 'd') { } 5 20 25
elsif ($f eq 'e') { } 0 20 20
elsif (exists $day_form{$f}) { } 0 20 20
elsif ($f eq 'w') { } 0 20 20
elsif ($f eq 'E') { } 0 20 20
elsif ($f eq 'H' or $f eq 'I') { } 4 16 20
elsif ($f eq 'k' or $f eq 'i') { } 0 16 16
elsif ($f eq 'p') { } 2 14 16
elsif ($f eq 'M') { } 4 10 14
elsif ($f eq 'S') { } 4 6 10
elsif (exists $z_form{$f}) { } 2 4 6
elsif ($f eq 's') { } 0 4 4
elsif ($f eq 'o') { } 0 4 4
elsif ($f eq 'G') { } 0 4 4
elsif ($f eq 'W') { } 0 4 4
elsif ($f eq 'L') { } 0 4 4
elsif ($f eq 'U') { } 0 4 4
elsif ($f eq 'c') { } 0 4 4
elsif ($f eq 'C' or $f eq 'u') { } 0 4 4
elsif ($f eq 'g') { } 0 4 4
elsif ($f eq 'D') { } 0 4 4
elsif ($f eq 'r') { } 2 2 4
elsif ($f eq 'R') { } 0 2 2
elsif ($f eq 'T' or $f eq 'X') { } 2 0 2
elsif ($f eq 'V') { } 0 0 0
elsif ($f eq 'Q') { } 0 0 0
elsif ($f eq 'q') { } 0 0 0
elsif ($f eq 'P') { } 0 0 0
elsif ($f eq 'O') { } 0 0 0
elsif ($f eq 'F') { } 0 0 0
elsif ($f eq 'K') { } 0 0 0
elsif ($f eq 'J') { } 0 0 0
elsif ($f eq 'x') { } 0 0 0
elsif ($f eq 't') { } 0 0 0
elsif ($f eq '%') { } 0 0 0
elsif ($f eq '+') { } 0 0 0
840 5 $re .= '(?<y>\d\d\d\d)';
841  
842 } elsif ($f eq 'y') {
843 0 $re .= '(?<y>\d\d)';
844  
845 } elsif ($f eq 'm') {
846 3 $re .= '(?<m>\d\d)';
847  
848 } elsif ($f eq 'f') {
849 0 $re .= '(?:(?<m>\d\d)| ?(?<m>\d))';
850  
851 } elsif (exists $mon_form{$f}) {
852 2 my $abb = $$dmb{'data'}{'rx'}{'month_abb'}[0];
853 2 my $nam = $$dmb{'data'}{'rx'}{'month_name'}[0];
854 2 $re .= "(?:(?<mon_name>$nam)|(?<mon_abb>$abb))";
855  
856 } elsif ($f eq 'j') {
857 0 $re .= '(?<doy>\d\d\d)';
858  
859 } elsif ($f eq 'd') {
860 5 $re .= '(?<d>\d\d)';
861  
862 } elsif ($f eq 'e') {
863 0 $re .= '(?:(?<d>\d\d)| ?(?<d>\d))';
864  
865 } elsif (exists $day_form{$f}) {
866 0 my $abb = $$dmb{'data'}{'rx'}{'day_abb'}[0];
867 0 my $name = $$dmb{'data'}{'rx'}{'day_name'}[0];
868 0 my $char = $$dmb{'data'}{'rx'}{'day_char'}[0];
869 0 $re .= "(?:(?<dow_name>$name)|(?<dow_abb>$abb)|(?<dow_char>$char))";
870  
871 } elsif ($f eq 'w') {
872 0 $re .= '(?<dow_num>[1-7])';
873  
874 } elsif ($f eq 'E') {
875 0 my $nth = $$dmb{'data'}{'rx'}{'nth'}[0];
876 0 $re .= "(?<nth>$nth)"
877  
878 ▶ } elsif ($f eq 'H' || $f eq 'I') {
Condition100%3/3
$f eq "H" or $f eq "I"
l!l&&r!l&&!r
2216
MC/DC100%2/2
$f eq "H" or $f eq "I"
$f eq "H" $f eq "I"
Truth table100%3/3
A or B
A= $f eq "H"B= $f eq "I"
ABresult
1X1
011
000
879 4 $re .= '(?<h>\d\d)';
880  
881 ▶ } elsif ($f eq 'k' || $f eq 'i') {
Condition33%1/3
$f eq "k" or $f eq "i"
l!l&&r!l&&!r
0016
MC/DC0%0/2
$f eq "k" or $f eq "i"
$f eq "k" $f eq "i"
Truth table33%1/3
A or B
A= $f eq "k"B= $f eq "i"
ABresult
1X1
011
000
882 0 $re .= '(?:(?<h>\d\d)| ?(?<h>\d))';
883  
884 } elsif ($f eq 'p') {
885 2 my $ampm = $$dmb{data}{rx}{ampm}[0];
886 2 $re .= "(?<ampm>$ampm)";
887  
888 } elsif ($f eq 'M') {
889 4 $re .= '(?<mn>\d\d)';
890  
891 } elsif ($f eq 'S') {
892 4 $re .= '(?<s>\d\d)';
893  
894 } elsif (exists $z_form{$f}) {
895 2 $re .= $dmt->_zrx('zrx');
896  
897 } elsif ($f eq 's') {
898 0 $re .= '(?<epochs>\d+)';
899  
900 } elsif ($f eq 'o') {
901 0 $re .= '(?<epocho>\d+)';
902  
903 } elsif ($f eq 'G') {
904 0 $re .= '(?<g>\d\d\d\d)';
905  
906 } elsif ($f eq 'W') {
907 0 $re .= '(?<w>\d\d)';
908  
909 } elsif ($f eq 'L') {
910 0 $re .= '(?<l>\d\d\d\d)';
911  
912 } elsif ($f eq 'U') {
913 0 $re .= '(?<u>\d\d)';
914  
915 } elsif ($f eq 'c') {
916 0 $format = '%a %b %e %H:%M:%S %Y' . $format;
917  
918 ▶ } elsif ($f eq 'C' || $f eq 'u') {
Condition33%1/3
$f eq "C" or $f eq "u"
l!l&&r!l&&!r
004
MC/DC0%0/2
$f eq "C" or $f eq "u"
$f eq "C" $f eq "u"
Truth table33%1/3
A or B
A= $f eq "C"B= $f eq "u"
ABresult
1X1
011
000
919 0 $format = '%a %b %e %H:%M:%S %Z %Y' . $format;
920  
921 } elsif ($f eq 'g') {
922 0 $format = '%a, %d %b %Y %H:%M:%S %Z' . $format;
923  
924 } elsif ($f eq 'D') {
925 0 $format = '%m/%d/%y' . $format;
926  
927 } elsif ($f eq 'r') {
928 2 $format = '%I:%M:%S %p' . $format;
929  
930 } elsif ($f eq 'R') {
931 0 $format = '%H:%M' . $format;
932  
933 ▶ } elsif ($f eq 'T' || $f eq 'X') {
Condition33%1/3
$f eq "T" or $f eq "X"
l!l&&r!l&&!r
200
MC/DC0%0/2
$f eq "T" or $f eq "X"
$f eq "T" $f eq "X"
Truth table33%1/3
A or B
A= $f eq "T"B= $f eq "X"
ABresult
1X1
011
000
934 2 $format = '%H:%M:%S' . $format;
935  
936 } elsif ($f eq 'V') {
937 0 $format = '%m%d%H%M%y' . $format;
938  
939 } elsif ($f eq 'Q') {
940 0 $format = '%Y%m%d' . $format;
941  
942 } elsif ($f eq 'q') {
943 0 $format = '%Y%m%d%H%M%S' . $format;
944  
945 } elsif ($f eq 'P') {
946 0 $format = '%Y%m%d%H:%M:%S' . $format;
947  
948 } elsif ($f eq 'O') {
949 0 $format = '%Y\\-%m\\-%dT%H:%M:%S' . $format;
950  
951 } elsif ($f eq 'F') {
952 0 $format = '%A, %B %e, %Y' . $format;
953  
954 } elsif ($f eq 'K') {
955 0 $format = '%Y-%j' . $format;
956  
957 } elsif ($f eq 'J') {
958 0 $format = '%G-W%W-%w' . $format;
959  
960 } elsif ($f eq 'x') {
961 0 ▶ if ($dmb->_config('dateformat') eq 'US') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dmb->_config('dateformat') eq 'US') { } 0 0 0
962 0 $format = '%m/%d/%y' . $format;
963 } else {
964 0 $format = '%d/%m/%y' . $format;
965 }
966  
967 } elsif ($f eq 't') {
968 0 $re .= "\t";
969  
970 } elsif ($f eq '%') {
971 0 $re .= '%';
972  
973 } elsif ($f eq '+') {
974 0 $re .= '\\+';
975 }
976 }
977  
978 7 ▶ if ($m != $d) {
Branch: 5 branches
BranchTrueFalseTotal
if ($m != $d) { } 0 7 7
elsif ($h || $mn || $s and not $h && $mn) { } 0 7 7
elsif ($ampm and not $h) { } 0 7 7
elsif ($G != $W) { } 0 7 7
elsif ($L != $U) { } 0 7 7
979 0 $err = 'Date not fully specified';
980 ▶ } elsif ( ($h || $mn || $s) && (! $h || ! $mn) ) {
Condition58%7/12
$h || $mn || $s and not $h && $mn
!ll&&!rl&&r
340
$h or $mn or $s
l!l&&r!l&&!r
403
$h or $mn
l!l&&r!l&&!r
403
$h && $mn
!ll&&!rl&&r
004
MC/DC0%0/5
$h || $mn || $s and not $h && $mn
$h $mn $s $h $mn
Truth table20%2/10
A or B or C and not(D && E)
A= $hB= $mnC= $sD= $hE= $mn
ABCDEresult
000XX0
1XX110
01X110
001110
1XX0X1
1XX101
01X0X1
01X101
0010X1
001101
981 0 $err = 'Time not fully specified';
982 ▶ } elsif ($ampm && ! $h) {
Condition66%2/3
$ampm and not $h
!ll&&!rl&&r
520
MC/DC0%0/2
$ampm and not $h
$ampm not $h
Truth table66%2/3
A and not(B)
A= $ampmB= not $h
ABresult
0X0
100
111
983 0 $err = 'Time not fully specified';
984 } elsif ($G != $W) {
985 0 $err = 'G/W must both be specified';
986 } elsif ($L != $U) {
987 0 $err = 'L/U must both be specified';
988 }
989  
990 7 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 7 7
991 0 $$dmb{'data'}{'format'}{$format} = [$err];
992 0 return ($err);
993 }
994  
995 7 $$dmb{'data'}{'format'}{$format} = [0, qr/$re/i];
996 7 return @{ $$dmb{'data'}{'format'}{$format} };
997 }
998 }
999  
1000 # This returns 1 if a given rule is set in the language _special_rules.
1001 #
1002 12717 ▶sub _parse_rule {
Subroutine _parse_rule: called CC=3 SCAR=11.0
1003 12717 my($self,$rule) = @_;
1004  
1005 12717 my $dmt = $$self{'tz'};
1006 12717 my $dmb = $$dmt{'base'};
1007  
1008 12717 ▶ if (exists $$dmb{'data'}{'lang'}{'_special_rules'} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dmb->{"data"}{"lang"}{"_special_rules"} and exists $dmb->{"data"}{"lang"}{"_special_rules"}{$rule}) 92 12625 12717
Condition66%2/3
exists $dmb->{"data"}{"lang"}{"_special_rules"} and exists $dmb->{"data"}{"lang"}{"_special_rules"}{$rule}
!ll&&!rl&&r
01262592
MC/DC50%1/2
exists $dmb->{"data"}{"lang"}{"_special_rules"} and exists $dmb->{"data"}{"lang"}{"_special_rules"}{$rule}
exists $dmb->{"data"}{"lang"}{"_special_rules"} exists $dmb->{"data"}{"lang"}{"_special_rules"}{$rule}
Truth table66%2/3
A and B
A= exists $dmb->{"data"}{"lang"}{"_special_rules"}B= exists $dmb->{"data"}{"lang"}{"_special_rules"}{$rule}
ABresult
0X0
100
111
1009 exists $$dmb{'data'}{'lang'}{'_special_rules'}{$rule}) {
1010 92 return $$dmb{'data'}{'lang'}{'_special_rules'}{$rule};
1011 }
1012 12625 return 0;
1013 }
1014  
1015 ########################################################################
1016 # DATE FORMATS
1017 ########################################################################
1018  
1019 4905 ▶sub _parse_check {
Subroutine _parse_check: called CC=21 SCAR=30.6
1020 4905 my($self,$caller,$instring,
1021 $y,$m,$d,$h,$mn,$s,$dow,$tzstring,$zone,$abb,$off) = @_;
1022 4905 my $dmt = $$self{'tz'};
1023 4905 my $dmb = $$dmt{'base'};
1024  
1025 # Check day_of_week for validity BEFORE converting 24:00:00 to the
1026 # next day
1027  
1028 4905 ▶ if ($dow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dow) 1105 3800 4905
1029 1105 my $tmp = $dmb->day_of_week([$y,$m,$d]);
1030 1105 ▶ if ($tmp != $dow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp != $dow) 4 1101 1105
1031 4 $$self{'err'} = "[$caller] Day of week invalid";
1032 4 return 1;
1033 }
1034 }
1035  
1036 # Handle 24:00:00 times.
1037  
1038 4901 ▶ if ($h == 24) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h == 24) 5 4896 4901
1039 5 ($h,$mn,$s) = (0,0,0);
1040 5 ($y,$m,$d) = @{ $dmb->calc_date_days([$y,$m,$d],1) };
1041 }
1042  
1043 4901 ▶ if (! $dmb->check([$y,$m,$d,$h,$mn,$s])) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dmb->check([$y, $m, $d, $h, $mn, $s])) 8 4893 4901
1044 8 $$self{'err'} = "[$caller] Invalid date";
1045 8 return 1;
1046 }
1047 4893 my $date = [$y+0,$m+0,$d+0,$h+0,$mn+0,$s+0];
1048  
1049 #
1050 # We need to check that the date is valid in a timezone. The
1051 # timezone may be referred to with $zone, $abb, or $off, and
1052 # unfortunately, $abb MAY be the name of an abbrevation OR a
1053 # zone in a few cases.
1054 #
1055  
1056 4893 my $zonename;
1057 4893 ▶ my $abbrev = (defined $abb ? lc($abb) : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $abb ? : 104 4789 4893
1058 4893 ▶ my $offset = (defined $off ? $dmb->_delta_convert('offset',$off) : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $off ? : 52 4841 4893
1059 4893 my @tmp;
1060  
1061 4893 ▶ if (defined($zone)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $zone) { } 8 4885 4893
elsif (defined $abb or defined $off) { } 143 4742 4885
1062 8 $zonename = $dmt->_zone($zone);
1063 8 ▶ if ($zonename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zonename) 8 0 8
1064 8 @tmp = $self->__parse_check($date,$zonename,$off,$abb);
1065 }
1066  
1067 ▶ } elsif (defined($abb) || defined($off)) {
Condition100%3/3
defined $abb or defined $off
l!l&&r!l&&!r
102414742
MC/DC100%2/2
defined $abb or defined $off
defined $abb defined $off
Truth table100%3/3
A or B
A= defined $abbB= defined $off
ABresult
1X1
011
000
1068  
1069 143 $zonename = $dmt->__zone($date,$offset,'',$abbrev,'');
1070 143 ▶ if ($zonename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zonename) 136 7 143
1071 136 @tmp = $self->__parse_check($date,$zonename,$off,$abb);
1072 }
1073  
1074 143 ▶ if (! @tmp && defined($abb)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @tmp and defined $abb) 4 139 143
Condition100%3/3
not @tmp and defined $abb
!ll&&!rl&&r
13634
MC/DC100%2/2
not @tmp and defined $abb
not @tmp defined $abb
Truth table100%3/3
not(A) and B
A= not @tmpB= defined $abb
ABresult
0X0
100
111
1075 4 my $tmp = $dmt->_zone($abb);
1076 4 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) 0 4 4
1077 0 $zonename = $tmp;
1078 0 @tmp = $self->__parse_check($date,$zonename,$off,undef);
1079 }
1080 }
1081  
1082 } else {
1083 4742 $zonename = $dmt->_now('tz');
1084 4742 ▶ if ($zonename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zonename) 4742 0 4742
1085 4742 @tmp = $self->__parse_check($date,$zonename,$off,$abb);
1086 }
1087 }
1088  
1089 4893 ▶ if (! $zonename) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($zonename) 7 4886 4893
1090 7 ▶ if (defined($zone)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $zone) { } 0 7 7
1091 0 $$self{'err'} = "[$caller] Unable to determine timezone: $zone";
1092 } else {
1093 7 $$self{'err'} = "[$caller] Unable to determine timezone";
1094 }
1095 7 return 1;
1096 }
1097  
1098 4886 ▶ if (! @tmp) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@tmp) 1 4885 4886
1099 1 $$self{'err'} = "[$caller] Invalid date in timezone";
1100 1 return 1;
1101 }
1102  
1103 # Store the date
1104  
1105 4885 my($a,$o,$isdst) = @tmp;
1106  
1107 4885 $self->set('zdate',$zonename,$date,$isdst);
1108 4885 ▶ return 1 if ($$self{'err'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} 0 4885 4885
1109  
1110 4885 $$self{'data'}{'in'} = $instring;
1111 4885 ▶ $$self{'data'}{'zin'} = $zone if (defined($zone));
Branch: 1 branch
BranchTrueFalseTotal
if defined $zone 8 4877 4885
1112  
1113 4885 return 0;
1114 }
1115  
1116 4886 ▶sub __parse_check {
Subroutine __parse_check: called CC=10 SCAR=23.0
1117 4886 my($self,$date,$zonename,$off,$abb) = @_;
1118 4886 my $dmt = $$self{'tz'};
1119 4886 my $dmb = $$dmt{'base'};
1120  
1121 4886 ▶ if (defined ($off)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $off) 49 4837 4886
1122 49 $off = $dmb->split('offset',$off);
1123 }
1124  
1125 4886 foreach my $isdst (0,1) {
1126 4890 my $per = $dmt->date_period($date,$zonename,1,$isdst);
1127 4890 ▶ next if (! $per);
Branch: 1 branch
BranchTrueFalseTotal
unless $per 2 4888 4890
1128 4888 my $a = $$per[4];
1129 4888 my $o = $$per[3];
1130  
1131 # If $abb is defined, it must match.
1132 4888 ▶ next if (defined $abb && lc($a) ne lc($abb));
Branch: 1 branch
BranchTrueFalseTotal
if defined $abb and lc $a ne lc $abb 2 4886 4888
Condition100%3/3
defined $abb and lc $a ne lc $abb
!ll&&!rl&&r
47861002
MC/DC100%2/2
defined $abb and lc $a ne lc $abb
defined $abb lc $a ne lc $abb
Truth table100%3/3
A and B
A= defined $abbB= lc $a ne lc $abb
ABresult
0X0
100
111
1133  
1134 # If $off is defined, it must match.
1135 4886 ▶ if (defined ($off)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $off) 50 4836 4886
1136 50 ▶ next if ($$off[0] != $$o[0] ||
Branch: 1 branch
BranchTrueFalseTotal
if $off->[0] != $o->[0] or $off->[1] != $o->[1] or $off->[2] != $o->[2] 1 49 50
Condition66%4/6
$off->[0] != $o->[0] or $off->[1] != $o->[1] or $off->[2] != $o->[2]
l!l&&r!l&&!r
1049
$off->[0] != $o->[0] or $off->[1] != $o->[1]
l!l&&r!l&&!r
1049
MC/DC33%1/3
$off->[0] != $o->[0] or $off->[1] != $o->[1] or $off->[2] != $o->[2]
$off->[0] != $o->[0] $off->[1] != $o->[1] $off->[2] != $o->[2]
Truth table50%2/4
A or B or C
A= $off->[0] != $o->[0]B= $off->[1] != $o->[1]C= $off->[2] != $o->[2]
ABCresult
1XX1
01X1
0011
0000
1137 $$off[1] != $$o[1] ||
1138 $$off[2] != $$o[2]);
1139 }
1140  
1141 4885 return ($a,$o,$isdst);
1142 }
1143 1 return ();
1144 }
1145  
1146 # Set up the regular expressions for ISO 8601 parsing. Returns the
1147 # requested regexp. $rx can be:
1148 # cdate : regular expression for a complete date
1149 # tdate : regular expression for a truncated date
1150 # ctime : regular expression for a complete time
1151 # ttime : regular expression for a truncated time
1152 # date : regular expression for a date only
1153 # time : regular expression for a time only
1154 # UNDEF : regular expression for a valid date and/or time
1155 #
1156 # Date matches are:
1157 # y m d doy w dow yod c
1158 # Time matches are:
1159 # h h24 mn s fh fm
1160 #
1161 3689 ▶sub _iso8601_rx {
Subroutine _iso8601_rx: called CC=9 SCAR=22.0
1162 3689 my($self,$rx) = @_;
1163 3689 my $dmt = $$self{'tz'};
1164 3689 my $dmb = $$dmt{'base'};
1165  
1166 return $$dmb{'data'}{'rx'}{'iso'}{$rx}
1167 3689 ▶ if (exists $$dmb{'data'}{'rx'}{'iso'}{$rx});
Branch: 1 branch
BranchTrueFalseTotal
if exists $dmb->{"data"}{"rx"}{"iso"}{$rx} 3418 271 3689
1168  
1169 271 ▶ if ($rx eq 'cdate' || $rx eq 'tdate') {
Branch: 5 branches
BranchTrueFalseTotal
if ($rx eq 'cdate' or $rx eq 'tdate') { } 88 183 271
elsif ($rx eq 'ctime' or $rx eq 'ttime') { } 77 106 183
elsif ($rx eq 'date') { } 29 77 106
elsif ($rx eq 'time') { } 1 76 77
elsif ($rx eq 'fulldate') { } 76 0 76
Condition66%2/3
$rx eq "cdate" or $rx eq "tdate"
l!l&&r!l&&!r
880183
MC/DC50%1/2
$rx eq "cdate" or $rx eq "tdate"
$rx eq "cdate" $rx eq "tdate"
Truth table66%2/3
A or B
A= $rx eq "cdate"B= $rx eq "tdate"
ABresult
1X1
011
000
1170  
1171 88 my $y4 = '(?<y>\d\d\d\d)';
1172 88 my $y2 = '(?<y>\d\d)';
1173 88 my $m = '(?<m>0[1-9]|1[0-2])';
1174 88 my $d = '(?<d>0[1-9]|[12][0-9]|3[01])';
1175 88 my $doy = '(?<doy>00[1-9]|0[1-9][0-9]|[1-2][0-9][0-9]|3[0-5][0-9]|36[0-6])';
1176 88 my $w = '(?<w>0[1-9]|[1-4][0-9]|5[0-3])';
1177 88 my $dow = '(?<dow>[1-7])';
1178 88 my $yod = '(?<yod>\d)';
1179 88 my $cc = '(?<c>\d\d)';
1180  
1181 88 my @cdaterx =
1182 (
1183 "${y4}${m}${d}", # CCYYMMDD
1184 "${y4}\\-${m}\\-${d}", # CCYY-MM-DD
1185 "\\-${y2}${m}${d}", # -YYMMDD
1186 "\\-${y2}\\-${m}\\-${d}", # -YY-MM-DD
1187 "\\-?${y2}${m}${d}", # YYMMDD
1188 "\\-?${y2}\\-${m}\\-${d}", # YY-MM-DD
1189 "\\-\\-${m}\\-?${d}", # --MM-DD --MMDD
1190 "\\-\\-\\-${d}", # ---DD
1191  
1192 "${y4}\\-?${doy}", # CCYY-DoY CCYYDoY
1193 "\\-?${y2}\\-?${doy}", # YY-DoY -YY-DoY
1194 # YYDoY -YYDoY
1195 "\\-${doy}", # -DoY
1196  
1197 "${y4}W${w}${dow}", # CCYYWwwD
1198 "${y4}\\-W${w}\\-${dow}", # CCYY-Www-D
1199 "\\-?${y2}W${w}${dow}", # YYWwwD -YYWwwD
1200 "\\-?${y2}\\-W${w}\\-${dow}", # YY-Www-D -YY-Www-D
1201  
1202 "\\-?${yod}W${w}${dow}", # YWwwD -YWwwD
1203 "\\-?${yod}\\-W${w}\\-${dow}", # Y-Www-D -Y-Www-D
1204 "\\-W${w}\\-?${dow}", # -Www-D -WwwD
1205 "\\-W\\-${dow}", # -W-D
1206 "\\-\\-\\-${dow}", # ---D
1207 );
1208 88 my $cdaterx = join('|',@cdaterx);
1209 88 $cdaterx = qr/(?:$cdaterx)/i;
1210  
1211 88 my @tdaterx =
1212 (
1213 "${y4}\\-${m}", # CCYY-MM
1214 "${y4}", # CCYY
1215 "\\-${y2}\\-?${m}", # -YY-MM -YYMM
1216 "\\-${y2}", # -YY
1217 "\\-\\-${m}", # --MM
1218  
1219 "${y4}\\-?W${w}", # CCYYWww CCYY-Www
1220 "\\-?${y2}\\-?W${w}", # YY-Www YYWww
1221 # -YY-Www -YYWww
1222 "\\-?W${w}", # -Www Www
1223  
1224 "${cc}", # CC
1225 );
1226 88 my $tdaterx = join('|',@tdaterx);
1227 88 $tdaterx = qr/(?:$tdaterx)/i;
1228  
1229 88 $$dmb{'data'}{'rx'}{'iso'}{'cdate'} = $cdaterx;
1230 88 $$dmb{'data'}{'rx'}{'iso'}{'tdate'} = $tdaterx;
1231  
1232 ▶ } elsif ($rx eq 'ctime' || $rx eq 'ttime') {
Condition66%2/3
$rx eq "ctime" or $rx eq "ttime"
l!l&&r!l&&!r
770106
MC/DC50%1/2
$rx eq "ctime" or $rx eq "ttime"
$rx eq "ctime" $rx eq "ttime"
Truth table66%2/3
A or B
A= $rx eq "ctime"B= $rx eq "ttime"
ABresult
1X1
011
000
1233  
1234 77 my $hh = '(?<h>[0-1][0-9]|2[0-3])';
1235 77 my $mn = '(?<mn>[0-5][0-9])';
1236 77 my $ss = '(?<s>[0-5][0-9])';
1237 77 my $h24a = '(?<h24>24(?::00){0,2})';
1238 77 my $h24b = '(?<h24>24(?:00){0,2})';
1239 77 my $h = '(?<h>[0-9])';
1240  
1241 77 my $fh = '(?:[\.,](?<fh>\d*))'; # fractional hours (keep)
1242 77 my $fm = '(?:[\.,](?<fm>\d*))'; # fractional seconds (keep)
1243 77 my $fs = '(?:[\.,]\d*)'; # fractional hours (discard)
1244  
1245 77 my $zrx = $dmt->_zrx('zrx');
1246  
1247 77 my @ctimerx =
1248 (
1249 "${hh}${mn}${ss}${fs}?", # HHMNSS[,S+]
1250 "${hh}:${mn}:${ss}${fs}?", # HH:MN:SS[,S+]
1251 "${hh}:?${mn}${fm}", # HH:MN,M+ HHMN,M+
1252 "${hh}${fh}", # HH,H+
1253 "\\-${mn}:?${ss}${fs}?", # -MN:SS[,S+] -MNSS[,S+]
1254 "\\-${mn}${fm}", # -MN,M+
1255 "\\-\\-${ss}${fs}?", # --SS[,S+]
1256 "${hh}:?${mn}", # HH:MN HHMN
1257 "${h24a}", # 24:00:00 24:00 24
1258 "${h24b}", # 240000 2400
1259 "${h}:${mn}:${ss}${fs}?", # H:MN:SS[,S+]
1260 "${h}:${mn}${fm}", # H:MN,M+
1261 );
1262 77 my $ctimerx = join('|',@ctimerx);
1263 77 $ctimerx = qr/(?:$ctimerx)(?:\s*$zrx)?/;
1264  
1265 77 my @ttimerx =
1266 (
1267 "${hh}", # HH
1268 "\\-${mn}", # -MN
1269 );
1270 77 my $ttimerx = join('|',@ttimerx);
1271 77 $ttimerx = qr/(?:$ttimerx)/;
1272  
1273 77 $$dmb{'data'}{'rx'}{'iso'}{'ctime'} = $ctimerx;
1274 77 $$dmb{'data'}{'rx'}{'iso'}{'ttime'} = $ttimerx;
1275  
1276 } elsif ($rx eq 'date') {
1277  
1278 29 my $cdaterx = $self->_iso8601_rx('cdate');
1279 29 my $tdaterx = $self->_iso8601_rx('tdate');
1280 29 $$dmb{'data'}{'rx'}{'iso'}{'date'} = qr/(?:$cdaterx|$tdaterx)/;
1281  
1282 } elsif ($rx eq 'time') {
1283  
1284 1 my $ctimerx = $self->_iso8601_rx('ctime');
1285 1 my $ttimerx = $self->_iso8601_rx('ttime');
1286 1 $$dmb{'data'}{'rx'}{'iso'}{'time'} = qr/(?:$ctimerx|$ttimerx)/;
1287  
1288 } elsif ($rx eq 'fulldate') {
1289  
1290 # A parseable string contains:
1291 # a complete date and complete time
1292 # a complete date and truncated time
1293 # a truncated date
1294 # a complete time
1295 # a truncated time
1296  
1297 # If the string contains both a time and date, they may be adjacent
1298 # or separated by:
1299 # whitespace
1300 # T (which must be followed by a number)
1301 # a dash
1302  
1303 76 my $cdaterx = $self->_iso8601_rx('cdate');
1304 76 my $tdaterx = $self->_iso8601_rx('tdate');
1305 76 my $ctimerx = $self->_iso8601_rx('ctime');
1306 76 my $ttimerx = $self->_iso8601_rx('ttime');
1307  
1308 76 my $sep = qr/(?:T|\-|\s*)/i;
1309  
1310 76 my $daterx = qr/^\s*(?: $cdaterx(?:$sep(?:$ctimerx|$ttimerx))? |
1311 $tdaterx |
1312 $ctimerx |
1313 $ttimerx
1314 )\s*$/x;
1315  
1316 76 $$dmb{'data'}{'rx'}{'iso'}{'fulldate'} = $daterx;
1317 }
1318  
1319 271 return $$dmb{'data'}{'rx'}{'iso'}{$rx};
1320 }
1321  
1322 2312 ▶sub _parse_datetime_iso8601 {
Subroutine _parse_datetime_iso8601: called CC=6 SCAR=17.9
1323 2312 my($self,$string,$noupdate) = @_;
1324 2312 my $dmt = $$self{'tz'};
1325 2312 my $dmb = $$dmt{'base'};
1326 2312 my $daterx = $self->_iso8601_rx('fulldate');
1327  
1328 2312 my($y,$m,$d,$h,$mn,$s,$tzstring,$zone,$abb,$off);
1329 2312 my($doy,$dow,$yod,$c,$w,$fh,$fm,$h24);
1330  
1331 2312 ▶ if ($string =~ $daterx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$daterx/) { } 314 1998 2312
1332 ($y,$m,$d,$h,$mn,$s,$doy,$dow,$yod,$c,$w,$fh,$fm,$h24,
1333 $tzstring,$zone,$abb,$off) =
1334 314 @+{qw(y m d h mn s doy dow yod c w fh fm h24 tzstring zone abb off)};
1335  
1336 314 ▶ if (defined $w || defined $dow) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $w or defined $dow) { } 39 275 314
elsif (defined $doy) { } 16 259 275
Condition100%3/3
defined $w or defined $dow
l!l&&r!l&&!r
354275
MC/DC100%2/2
defined $w or defined $dow
defined $w defined $dow
Truth table100%3/3
A or B
A= defined $wB= defined $dow
ABresult
1X1
011
000
1337 39 ($y,$m,$d) = $self->_def_date_dow($y,$w,$dow,$noupdate);
1338 } elsif (defined $doy) {
1339 16 ($y,$m,$d) = $self->_def_date_doy($y,$doy,$noupdate);
1340 } else {
1341 259 ▶ $y = $c . '00' if (defined $c);
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 0 259 259
1342 259 ($y,$m,$d) = $self->_def_date($y,$m,$d,$noupdate);
1343 }
1344  
1345 314 ($h,$mn,$s) = $self->_time($h,$mn,$s,$fh,$fm,$h24,undef,$noupdate);
1346 } else {
1347 1998 return (0);
1348 }
1349  
1350 314 return (1,$y,$m,$d,$h,$mn,$s,$tzstring,$zone,$abb,$off);
1351 }
1352  
1353 1012 ▶sub _parse_date_iso8601 {
Subroutine _parse_date_iso8601: called CC=6 SCAR=17.9
1354 1012 my($self,$string,$noupdate) = @_;
1355 1012 my $dmt = $$self{'tz'};
1356 1012 my $dmb = $$dmt{'base'};
1357 1012 my $daterx = $self->_iso8601_rx('date');
1358  
1359 1012 my($y,$m,$d);
1360 1012 my($doy,$dow,$yod,$c,$w);
1361  
1362 1012 ▶ if ($string =~ /^$daterx$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /^$daterx$/) { } 70 942 1012
1363 ($y,$m,$d,$doy,$dow,$yod,$c,$w) =
1364 70 @+{qw(y m d doy dow yod c w)};
1365  
1366 70 ▶ if (defined $w || defined $dow) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $w or defined $dow) { } 30 40 70
elsif (defined $doy) { } 7 33 40
Condition100%3/3
defined $w or defined $dow
l!l&&r!l&&!r
26440
MC/DC100%2/2
defined $w or defined $dow
defined $w defined $dow
Truth table100%3/3
A or B
A= defined $wB= defined $dow
ABresult
1X1
011
000
1367 30 ($y,$m,$d) = $self->_def_date_dow($y,$w,$dow,$noupdate);
1368 } elsif (defined $doy) {
1369 7 ($y,$m,$d) = $self->_def_date_doy($y,$doy,$noupdate);
1370 } else {
1371 33 ▶ $y = $c . '00' if (defined $c);
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 0 33 33
1372 33 ($y,$m,$d) = $self->_def_date($y,$m,$d,$noupdate);
1373 }
1374 } else {
1375 942 return (0);
1376 }
1377  
1378 70 return (1,$y,$m,$d);
1379 }
1380  
1381 # Handle all of the time fields.
1382 #
1383 170 ▶no integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
1384 1447 ▶sub _time {
Subroutine _time: called CC=11 SCAR=24.1
1385 1447 my($self,$h,$mn,$s,$fh,$fm,$h24,$ampm,$noupdate) = @_;
1386  
1387 1447 ▶ if (defined($ampm) && $ampm) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ampm and $ampm) 76 1371 1447
Condition66%2/3
defined $ampm and $ampm
!ll&&!rl&&r
1371076
MC/DC50%1/2
defined $ampm and $ampm
defined $ampm $ampm
Truth table66%2/3
A and B
A= defined $ampmB= $ampm
ABresult
0X0
100
111
1388 76 my $dmt = $$self{'tz'};
1389 76 my $dmb = $$dmt{'base'};
1390 76 ▶ if ($$dmb{'data'}{'wordmatch'}{'ampm'}{lc($ampm)} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dmb->{'data'}{'wordmatch'}{'ampm'}{lc $ampm} == 2) { } 70 6 76
1391 # pm times
1392 70 ▶ $h+=12 unless ($h==12);
Branch: 1 branch
BranchTrueFalseTotal
unless $h == 12 70 0 70
1393 } else {
1394 # am times
1395 6 ▶ $h=0 if ($h==12);
Branch: 1 branch
BranchTrueFalseTotal
if $h == 12 1 5 6
1396 }
1397 }
1398  
1399 1447 ▶ if (defined $h24) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $h24) { } 4 1443 1447
elsif (defined $fh and $fh ne '') { } 12 1431 1443
elsif (defined $fm and $fm ne '') { } 8 2846 2854
1400 4 return(24,0,0);
1401 ▶ } elsif (defined $fh && $fh ne "") {
Condition66%2/3
defined $fh and $fh ne ""
!ll&&!rl&&r
1431012
MC/DC50%1/2
defined $fh and $fh ne ""
defined $fh $fh ne ""
Truth table66%2/3
A and B
A= defined $fhB= $fh ne ""
ABresult
0X0
100
111
1402 12 $fh = "0.$fh";
1403 12 $s = int($fh * 3600);
1404 12 $mn = int($s/60);
1405 12 $s -= $mn*60;
1406 ▶ } elsif (defined $fm && $fm ne "") {
Condition66%2/3
defined $fm and $fm ne ""
!ll&&!rl&&r
142308
MC/DC50%1/2
defined $fm and $fm ne ""
defined $fm $fm ne ""
Truth table66%2/3
A and B
A= defined $fmB= $fm ne ""
ABresult
0X0
100
111
1407 8 $fm = "0.$fm";
1408 8 $s = int($fm*60);
1409 }
1410 1443 ($h,$mn,$s) = $self->_def_time($h,$mn,$s,$noupdate);
1411 1443 return($h,$mn,$s);
1412 }
1413 170 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
1414  
1415 # Set up the regular expressions for other date and time formats. Returns the
1416 # requested regexp.
1417 #
1418 500 ▶sub _other_rx {
Subroutine _other_rx: called CC=29 SCAR=33.7
1419 500 my($self,$rx) = @_;
1420 500 my $dmt = $$self{'tz'};
1421 500 my $dmb = $$dmt{'base'};
1422 500 ▶ $rx = '_' if (! defined $rx);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rx 0 500 500
1423  
1424 500 ▶ if ($rx eq 'time') {
Branch: 8 branches
BranchTrueFalseTotal
if ($rx eq 'time') { } 62 438 500
elsif ($rx eq 'common_1') { } 73 365 438
elsif ($rx eq 'common_2') { } 73 292 365
elsif ($rx eq 'truncated') { } 35 257 292
elsif ($rx eq 'dow') { } 73 184 257
elsif ($rx eq 'ignore') { } 73 111 184
elsif ($rx eq 'miscdatetime') { } 65 46 111
elsif ($rx eq 'misc') { } 46 0 46
1425  
1426 62 my $h24 = '(?<h>2[0-3]|1[0-9]|0?[0-9])'; # 0-23 00-23
1427 62 my $h12 = '(?<h>1[0-2]|0?[1-9])'; # 1-12 01-12
1428 62 my $mn = '(?<mn>[0-5][0-9])'; # 00-59
1429 62 my $ss = '(?<s>[0-5][0-9])'; # 00-59
1430  
1431 # how to express fractions
1432  
1433 62 my($f1,$f2,$sepfr);
1434 62 ▶ if (exists $$dmb{'data'}{'rx'}{'sepfr'} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dmb->{'data'}{'rx'}{'sepfr'} and $dmb->{'data'}{'rx'}{'sepfr'}) { } 3 59 62
Condition66%2/3
exists $dmb->{"data"}{"rx"}{"sepfr"} and $dmb->{"data"}{"rx"}{"sepfr"}
!ll&&!rl&&r
0593
MC/DC50%1/2
exists $dmb->{"data"}{"rx"}{"sepfr"} and $dmb->{"data"}{"rx"}{"sepfr"}
exists $dmb->{"data"}{"rx"}{"sepfr"} $dmb->{"data"}{"rx"}{"sepfr"}
Truth table66%2/3
A and B
A= exists $dmb->{"data"}{"rx"}{"sepfr"}B= $dmb->{"data"}{"rx"}{"sepfr"}
ABresult
0X0
100
111
1435 $$dmb{'data'}{'rx'}{'sepfr'}) {
1436 3 $sepfr = $$dmb{'data'}{'rx'}{'sepfr'};
1437 } else {
1438 59 $sepfr = '';
1439 }
1440  
1441 62 ▶ if ($sepfr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sepfr) { } 3 59 62
1442 3 $f1 = "(?:[.,]|$sepfr)";
1443 3 $f2 = "(?:[.,:]|$sepfr)";
1444 } else {
1445 59 $f1 = "[.,]";
1446 59 $f2 = "[.,:]";
1447 }
1448 62 my $fh = "(?:$f1(?<fh>\\d*))"; # fractional hours (keep)
1449 62 my $fm = "(?:$f1(?<fm>\\d*))"; # fractional minutes (keep)
1450 62 my $fs = "(?:$f2\\d*)"; # fractional seconds
1451  
1452 # AM/PM
1453  
1454 62 my($ampm);
1455 62 ▶ if (exists $$dmb{'data'}{'rx'}{'ampm'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dmb->{"data"}{"rx"}{"ampm"}) 62 0 62
1456 62 $ampm = "(?:\\s*(?<ampm>$$dmb{data}{rx}{ampm}[0]))";
1457 }
1458  
1459 # H:MN and MN:S separators
1460  
1461 62 my @hm = ("\Q:\E");
1462 62 my @ms = ("\Q:\E");
1463 62 ▶ if ($dmb->_config('periodtimesep')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dmb->_config("periodtimesep")) 1 61 62
1464 1 push(@hm,"\Q.\E");
1465 1 push(@ms,"\Q.\E");
1466 }
1467 62 ▶ if (exists $$dmb{'data'}{'rx'}{'sephm'} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dmb->{"data"}{"rx"}{"sephm"} and defined $dmb->{"data"}{"rx"}{"sephm"} and exists $dmb->{"data"}{"rx"}{"sepms"} and defined $dmb->{"data"}{"rx"}{"sepms"}) 8 54 62
Condition66%6/9
exists $dmb->{"data"}{"rx"}{"sephm"} and defined $dmb->{"data"}{"rx"}{"sephm"} and exists $dmb->{"data"}{"rx"}{"sepms"} and defined $dmb->{"data"}{"rx"}{"sepms"}
!ll&&!rl&&r
5408
exists $dmb->{"data"}{"rx"}{"sephm"} and defined $dmb->{"data"}{"rx"}{"sephm"} and exists $dmb->{"data"}{"rx"}{"sepms"}
!ll&&!rl&&r
5408
exists $dmb->{"data"}{"rx"}{"sephm"} and defined $dmb->{"data"}{"rx"}{"sephm"}
!ll&&!rl&&r
0548
MC/DC25%1/4
exists $dmb->{"data"}{"rx"}{"sephm"} and defined $dmb->{"data"}{"rx"}{"sephm"} and exists $dmb->{"data"}{"rx"}{"sepms"} and defined $dmb->{"data"}{"rx"}{"sepms"}
exists $dmb->{"data"}{"rx"}{"sephm"} defined $dmb->{"data"}{"rx"}{"sephm"} exists $dmb->{"data"}{"rx"}{"sepms"} defined $dmb->{"data"}{"rx"}{"sepms"}
Truth table40%2/5
A and B and C and D
A= exists $dmb->{"data"}{"rx"}{"sephm"}B= defined $dmb->{"data"}{"rx"}{"sephm"}C= exists $dmb->{"data"}{"rx"}{"sepms"}D= defined $dmb->{"data"}{"rx"}{"sepms"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1468 defined $$dmb{'data'}{'rx'}{'sephm'} &&
1469 exists $$dmb{'data'}{'rx'}{'sepms'} &&
1470 defined $$dmb{'data'}{'rx'}{'sepms'}) {
1471 8 push(@hm,@{ $$dmb{'data'}{'rx'}{'sephm'} });
1472 8 push(@ms,@{ $$dmb{'data'}{'rx'}{'sepms'} });
1473 }
1474  
1475 # How to express the time
1476 # matches = (H, FH, MN, FMN, S, AM, TZSTRING, ZONE, ABB, OFF, ABB)
1477  
1478 62 my @timerx;
1479  
1480 62 ▶ for (my $i=0; $i<=$#hm; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#hm) 72 62 134
1481 72 my $hm = $hm[$i];
1482 72 my $ms = $ms[$i];
1483 72 ▶ push(@timerx,
Branch: 1 branch
BranchTrueFalseTotal
if $ampm 72 0 72
1484 "${h12}$hm${mn}$ms${ss}${fs}?${ampm}?", # H12:MN:SS[,S+] [AM]
1485 ) if ($ampm);
1486  
1487 72 push(@timerx,
1488 "${h24}$hm${mn}$ms${ss}${fs}?", # H24:MN:SS[,S+]
1489 "(?<h>24)$hm(?<mn>00)$ms(?<s>00)", # 24:00:00
1490 );
1491 }
1492 62 ▶ for (my $i=0; $i<=$#hm; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#hm) 72 62 134
1493 72 my $hm = $hm[$i];
1494 72 my $ms = $ms[$i];
1495 72 ▶ push(@timerx,
Branch: 1 branch
BranchTrueFalseTotal
if $ampm 72 0 72
1496 "${h12}$hm${mn}${fm}${ampm}?", # H12:MN,M+ [AM]
1497 ) if ($ampm);
1498 72 push(@timerx,
1499 "${h24}$hm${mn}${fm}", # H24:MN,M+
1500 );
1501 }
1502 62 ▶ for (my $i=0; $i<=$#hm; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#hm) 72 62 134
1503 72 my $hm = $hm[$i];
1504 72 my $ms = $ms[$i];
1505 72 ▶ push(@timerx,
Branch: 1 branch
BranchTrueFalseTotal
if $ampm 72 0 72
1506 "${h12}$hm${mn}${ampm}?", # H12:MN [AM]
1507 ) if ($ampm);
1508 72 push(@timerx,
1509 "${h24}$hm${mn}", # H24:MN
1510 "(?<h>24)$hm(?<mn>00)", # 24:00
1511 );
1512 }
1513  
1514 62 ▶ push(@timerx,
Branch: 1 branch
BranchTrueFalseTotal
if $ampm 62 0 62
1515 "${h12}${fh}${ampm}", # H12,H+ AM
1516 "${h12}${ampm}", # H12 AM
1517 ) if ($ampm);
1518 62 push(@timerx,
1519 "${h24}${fh}", # H24,H+
1520 );
1521  
1522 62 my $timerx = join('|',@timerx);
1523 62 my $zrx = $dmt->_zrx('zrx');
1524 62 my $at = $$dmb{'data'}{'rx'}{'at'};
1525 62 my $atrx = qr/(?:^|\s+)(?:$at)\s+/;
1526 62 $timerx = qr/(?:$atrx|^|\s+)(?:$timerx)(?:\s*$zrx)?(?:\s+|$)/i;
1527  
1528 62 $$dmb{'data'}{'rx'}{'other'}{$rx} = $timerx;
1529  
1530 } elsif ($rx eq 'common_1') {
1531  
1532 # These are of the format M/D/Y
1533  
1534 # Do NOT replace <m> and <d> with a regular expression to
1535 # match 1-12 since the DateFormat config may reverse the two.
1536 73 my $y4 = '(?<y>\d\d\d\d)';
1537 73 my $y2 = '(?<y>\d\d)';
1538 73 my $m = '(?<m>\d\d?)';
1539 73 my $d = '(?<d>\d\d?)';
1540 73 my $sep = '(?<sep>[\s\.\/\-])';
1541  
1542 73 my @daterx =
1543 (
1544 "${m}${sep}${d}\\k<sep>$y4", # M/D/YYYY
1545 "${m}${sep}${d}\\k<sep>$y2", # M/D/YY
1546 "${m}${sep}${d}", # M/D
1547 );
1548 73 my $daterx = join('|',@daterx);
1549  
1550 73 $daterx = qr/^\s*(?:$daterx)\s*$/;
1551 73 $$dmb{'data'}{'rx'}{'other'}{$rx} = $daterx;
1552  
1553 } elsif ($rx eq 'common_2') {
1554  
1555 73 my $abb = $$dmb{'data'}{'rx'}{'month_abb'}[0];
1556 73 my $nam = $$dmb{'data'}{'rx'}{'month_name'}[0];
1557  
1558 73 my $y4 = '(?<y>\d\d\d\d)';
1559 73 my $y2 = '(?<y>\d\d)';
1560 73 my $m = '(?<m>\d\d?)';
1561 73 my $d = '(?<d>\d\d?)';
1562 73 my $dd = '(?<d>\d\d)';
1563 73 my $mmm = "(?:(?<mmm>$abb)|(?<month>$nam))";
1564 73 my $sep = '(?<sep>[\s\.\/\-])';
1565  
1566 73 my $format_mmmyyyy = $dmb->_config('format_mmmyyyy');
1567  
1568 73 my @daterx = ();
1569 73 push(@daterx,
1570 "${y4}${sep}${m}\\k<sep>$d", # YYYY/M/D
1571 "${mmm}\\s*${dd}\\s*${y4}", # mmmDDYYYY
1572 );
1573 73 ▶ push(@daterx,
Branch: 1 branch
BranchTrueFalseTotal
unless $format_mmmyyyy 69 4 73
1574 "${mmm}\\s*${dd}\\s*${y2}", # mmmDDYY
1575 ) if (! $format_mmmyyyy);
1576 73 push(@daterx,
1577 "${mmm}\\s*${d}", # mmmD
1578 "${d}\\s*${mmm}\\s*${y4}", # DmmmYYYY
1579 "${d}\\s*${mmm}\\s*${y2}", # DmmmYY
1580 "${d}\\s*${mmm}", # Dmmm
1581 "${y4}\\s*${mmm}\\s*${d}", # YYYYmmmD
1582  
1583 "${mmm}${sep}${d}\\k<sep>${y4}", # mmm/D/YYYY
1584 "${mmm}${sep}${d}\\k<sep>${y2}", # mmm/D/YY
1585 "${mmm}${sep}${d}", # mmm/D
1586 "${d}${sep}${mmm}\\k<sep>${y4}", # D/mmm/YYYY
1587 "${d}${sep}${mmm}\\k<sep>${y2}", # D/mmm/YY
1588 "${d}${sep}${mmm}", # D/mmm
1589 "${y4}${sep}${mmm}\\k<sep>${d}", # YYYY/mmm/D
1590  
1591 "${mmm}${sep}?${d}\\s+${y2}", # mmmD YY mmm/D YY
1592 "${mmm}${sep}?${d}\\s+${y4}", # mmmD YYYY mmm/D YYYY
1593 "${d}${sep}?${mmm}\\s+${y2}", # Dmmm YY D/mmm YY
1594 "${d}${sep}?${mmm}\\s+${y4}", # Dmmm YYYY D/mmm YYYY
1595  
1596 "${y2}\\s+${mmm}${sep}?${d}", # YY mmmD YY mmm/D
1597 "${y4}\\s+${mmm}${sep}?${d}", # YYYY mmmD YYYY mmm/D
1598 "${y2}\\s+${d}${sep}?${mmm}", # YY Dmmm YY D/mmm
1599 "${y4}\\s+${d}${sep}?${mmm}", # YYYY Dmmm YYYY D/mmm
1600  
1601 "${y4}:${m}:${d}", # YYYY:MM:DD
1602 );
1603 73 my $daterx = join('|',@daterx);
1604  
1605 73 $daterx = qr/^\s*(?:$daterx)\s*$/i;
1606 73 $$dmb{'data'}{'rx'}{'other'}{$rx} = $daterx;
1607  
1608 } elsif ($rx eq 'truncated') {
1609  
1610 35 my $abb = $$dmb{'data'}{'rx'}{'month_abb'}[0];
1611 35 my $nam = $$dmb{'data'}{'rx'}{'month_name'}[0];
1612  
1613 35 my $y4 = '(?<y>\d\d\d\d)';
1614 35 my $mmm = "(?:(?<mmm>$abb)|(?<month>$nam))";
1615 35 my $sep = '(?<sep>[\s\.\/\-])';
1616  
1617 35 my $format_mmmyyyy = $dmb->_config('format_mmmyyyy');
1618  
1619 35 my @daterx = ();
1620 35 ▶ push(@daterx,
Branch: 1 branch
BranchTrueFalseTotal
if $format_mmmyyyy 4 31 35
1621 "${mmm}\\s*${y4}", # mmmYYYY
1622 "${y4}\\s*${mmm}", # YYYYmmm
1623  
1624 "${y4}${sep}${mmm}", # YYYY/mmm
1625 "${mmm}${sep}${y4}", # mmm/YYYY
1626 ) if ($format_mmmyyyy);
1627  
1628 35 ▶ if (@daterx) {
Branch: 1 branch
BranchTrueFalseTotal
if (@daterx) { } 4 31 35
1629 4 my $daterx = join('|',@daterx);
1630 4 $daterx = qr/^\s*(?:$daterx)\s*$/i;
1631 4 $$dmb{'data'}{'rx'}{'other'}{$rx} = $daterx;
1632 } else {
1633 31 $$dmb{'data'}{'rx'}{'other'}{$rx} = '';
1634 }
1635  
1636 } elsif ($rx eq 'dow') {
1637  
1638 73 my $day_abb = $$dmb{'data'}{'rx'}{'day_abb'}[0];
1639 73 my $day_name = $$dmb{'data'}{'rx'}{'day_name'}[0];
1640  
1641 73 my $on = $$dmb{'data'}{'rx'}{'on'};
1642 73 my $onrx = qr/(?:^|\s+)(?:$on)\s+/;
1643 73 my $dowrx = qr/(?:$onrx|^|\s+)(?<dow>$day_name|$day_abb)($|\s+)/i;
1644  
1645 73 $$dmb{'data'}{'rx'}{'other'}{$rx} = $dowrx;
1646  
1647 } elsif ($rx eq 'ignore') {
1648  
1649 73 my $of = $$dmb{'data'}{'rx'}{'of'};
1650  
1651 73 my $ignrx = qr/(?:^|\s+)(?<of>$of)(\s+|$)/;
1652 73 $$dmb{'data'}{'rx'}{'other'}{$rx} = $ignrx;
1653  
1654 } elsif ($rx eq 'miscdatetime') {
1655  
1656 65 my $special = $$dmb{'data'}{'rx'}{'offset_time'}[0];
1657  
1658 65 $special = "(?<special>$special)";
1659 65 my $secs = "(?<epoch>[-+]?\\d+)";
1660 65 my $abb = $$dmb{'data'}{'rx'}{'month_abb'}[0];
1661 65 my $mmm = "(?<mmm>$abb)";
1662 65 my $y4 = '(?<y>\d\d\d\d)';
1663 65 my $dd = '(?<d>\d\d)';
1664 65 my $h24 = '(?<h>2[0-3]|[01][0-9])'; # 00-23
1665 65 my $mn = '(?<mn>[0-5][0-9])'; # 00-59
1666 65 my $ss = '(?<s>[0-5][0-9])'; # 00-59
1667 65 my $offrx = $dmt->_zrx('offrx');
1668 65 my $zrx = $dmt->_zrx('zrx');
1669  
1670 65 my @daterx =
1671 (
1672 "${special}", # now
1673 "${special}\\s+${zrx}", # now EDT
1674  
1675 "epoch\\s+$secs", # epoch SECS
1676 "epoch\\s+$secs\\s+${zrx}", # epoch SECS EDT
1677  
1678 "${dd}\\/${mmm}\\/${y4}:${h24}:${mn}:${ss}\\s*${offrx}",
1679 # Common log format: 10/Oct/2000:13:55:36 -0700
1680 );
1681 65 my $daterx = join('|',@daterx);
1682  
1683 65 $daterx = qr/^\s*(?:$daterx)\s*$/i;
1684 65 $$dmb{'data'}{'rx'}{'other'}{$rx} = $daterx;
1685  
1686 } elsif ($rx eq 'misc') {
1687  
1688 46 my $abb = $$dmb{'data'}{'rx'}{'month_abb'}[0];
1689 46 my $nam = $$dmb{'data'}{'rx'}{'month_name'}[0];
1690 46 my $next = $$dmb{'data'}{'rx'}{'nextprev'}[0];
1691 46 my $last = $$dmb{'data'}{'rx'}{'last'};
1692 46 my $yf = $$dmb{data}{rx}{fields}[1];
1693 46 my $mf = $$dmb{data}{rx}{fields}[2];
1694 46 my $wf = $$dmb{data}{rx}{fields}[3];
1695 46 my $df = $$dmb{data}{rx}{fields}[4];
1696 46 my $nth = $$dmb{'data'}{'rx'}{'nth'}[0];
1697 46 my $nth_wom = $$dmb{'data'}{'rx'}{'nth_wom'}[0];
1698 46 my $special = $$dmb{'data'}{'rx'}{'offset_date'}[0];
1699  
1700 46 my $y = '(?:(?<y>\d\d\d\d)|(?<y>\d\d))';
1701 46 my $mmm = "(?:(?<mmm>$abb)|(?<month>$nam))";
1702 46 $next = "(?<next>$next)";
1703 46 $last = "(?<last>$last)";
1704 46 $yf = "(?<field_y>$yf)";
1705 46 $mf = "(?<field_m>$mf)";
1706 46 $wf = "(?<field_w>$wf)";
1707 46 $df = "(?<field_d>$df)";
1708 46 my $fld = "(?:$yf|$mf|$wf)";
1709 46 $nth = "(?<nth>$nth)";
1710 46 $nth_wom = "(?<nth>$nth_wom)";
1711 46 $special = "(?<special>$special)";
1712  
1713 46 my @daterx =
1714 (
1715 "${mmm}\\s+${nth}\\s*$y?", # Dec 1st [1970]
1716 "${nth}\\s+${mmm}\\s*$y?", # 1st Dec [1970]
1717 "$y\\s+${mmm}\\s+${nth}", # 1970 Dec 1st
1718 "$y\\s+${nth}\\s+${mmm}", # 1970 1st Dec
1719  
1720 "${next}\\s+${fld}", # next year, next month, next week
1721 "${next}", # next friday
1722  
1723 "${last}\\s+${mmm}\\s*$y?", # last friday in october 95
1724 "${last}\\s+${df}\\s+${mmm}\\s*$y?",
1725 # last day in october 95
1726 "${last}\\s*$y?", # last friday in 95
1727  
1728 "${nth_wom}\\s+${mmm}\\s*$y?", # nth DoW in MMM [YYYY]
1729 "${nth}\\s*$y?", # nth DoW in [YYYY]
1730  
1731 "${nth}\\s+$df\\s+${mmm}\\s*$y?",
1732 # nth day in MMM [YYYY]
1733  
1734 "${nth}\\s+${wf}\\s*$y?", # DoW Nth week [YYYY]
1735 "${wf}\\s+(?<n>\\d+)\\s*$y?", # DoW week N [YYYY]
1736  
1737 "${special}", # today, tomorrow
1738 "${special}\\s+${wf}", # today week
1739 # British: same as 1 week from today
1740  
1741 "${nth}", # nth
1742  
1743 "${wf}", # monday week
1744 # British: same as 'in 1 week on monday'
1745 );
1746 46 my $daterx = join('|',@daterx);
1747  
1748 46 $daterx = qr/^\s*(?:$daterx)\s*$/i;
1749 46 $$dmb{'data'}{'rx'}{'other'}{$rx} = $daterx;
1750  
1751 }
1752  
1753 500 return $$dmb{'data'}{'rx'}{'other'}{$rx};
1754 }
1755  
1756 2009 ▶sub _parse_time {
Subroutine _parse_time: called CC=22 SCAR=31.3
1757 2009 my($self,$caller,$string,$noupdate,%opts) = @_;
1758 2009 my $dmt = $$self{'tz'};
1759 2009 my $dmb = $$dmt{'base'};
1760  
1761 2009 my($timerx,$h,$mn,$s,$fh,$fm,$h24,$ampm,$tzstring,$zone,$abb,$off);
1762 2009 my $got_time = 0;
1763  
1764 # Check for ISO 8601 time
1765 #
1766 # This is only called via. parse_time (parse_date uses a regexp
1767 # that matches a full ISO 8601 date/time instead of parsing them
1768 # separately. Since some ISO 8601 times are a substring of non-ISO
1769 # 8601 times (i.e. 12:30 is a substring of '12:30 PM'), we need to
1770 # match entire strings here.
1771  
1772 2009 ▶ if ($caller eq 'parse_time') {
Branch: 1 branch
BranchTrueFalseTotal
if ($caller eq "parse_time") 30 1979 2009
1773 $timerx = (exists $$dmb{'data'}{'rx'}{'iso'}{'time'} ?
1774 30 ▶ $$dmb{'data'}{'rx'}{'iso'}{'time'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $dmb->{'data'}{'rx'}{'iso'}{'time'} ? : 29 1 30
1775 $self->_iso8601_rx('time'));
1776  
1777 30 ▶ if (! exists $opts{'noiso8601'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts{"noiso8601"}) 30 0 30
1778 30 ▶ if ($string =~ s/^\s*$timerx\s*$//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/^\s*$timerx\s*$//) 14 16 30
1779 ($h,$fh,$mn,$fm,$s,$ampm,$tzstring,$zone,$abb,$off) =
1780 14 @+{qw(h fh mn fm s ampm tzstring zone abb off)};
1781  
1782 14 ($h,$mn,$s) = $self->_def_time($h,$mn,$s,$noupdate);
1783 14 ▶ $h24 = 1 if ($h == 24 && $mn == 0 && $s == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $h == 24 and $mn == 0 and $s == 0 0 14 14
Condition33%2/6
$h == 24 and $mn == 0 and $s == 0
!ll&&!rl&&r
1400
$h == 24 and $mn == 0
!ll&&!rl&&r
1400
MC/DC0%0/3
$h == 24 and $mn == 0 and $s == 0
$h == 24 $mn == 0 $s == 0
Truth table25%1/4
A and B and C
A= $h == 24B= $mn == 0C= $s == 0
ABCresult
0XX0
10X0
1100
1111
1784 14 $string =~ s/\s*$//;
1785 14 $got_time = 1;
1786 }
1787 }
1788 }
1789  
1790 # Make time substitutions (i.e. noon => 12:00:00)
1791  
1792 2009 ▶ if (! $got_time &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($got_time or exists $opts{"noother"}) 1995 14 2009
Condition66%2/3
$got_time or exists $opts{"noother"}
l!l&&r!l&&!r
1401995
MC/DC50%1/2
$got_time or exists $opts{"noother"}
$got_time exists $opts{"noother"}
Truth table66%2/3
A or B
A= $got_timeB= exists $opts{"noother"}
ABresult
1X1
011
000
1793 ! exists $opts{'noother'}) {
1794 1995 my @rx = @{ $$dmb{'data'}{'rx'}{'times'} };
1795 1995 shift(@rx);
1796 1995 foreach my $rx (@rx) {
1797 4079 ▶ if ($string =~ $rx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$rx/) 179 3900 4079
1798 179 my $repl = $$dmb{'data'}{'wordmatch'}{'times'}{lc($1)};
1799 179 $string =~ s/$rx/$repl/g;
1800 }
1801 }
1802 }
1803  
1804 # Check to see if there is a time in the string
1805  
1806 2009 ▶ if (! $got_time) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($got_time) 1995 14 2009
1807 $timerx = (exists $$dmb{'data'}{'rx'}{'other'}{'time'} ?
1808 1995 ▶ $$dmb{'data'}{'rx'}{'other'}{'time'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $dmb->{'data'}{'rx'}{'other'}{'time'} ? : 1933 62 1995
1809 $self->_other_rx('time'));
1810  
1811 1995 ▶ if ($string =~ s/$timerx/ /) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/$timerx/ /) 1124 871 1995
1812 ($h,$fh,$mn,$fm,$s,$ampm,$tzstring,$zone,$abb,$off) =
1813 1124 @+{qw(h fh mn fm s ampm tzstring zone abb off)};
1814  
1815 1124 ($h,$mn,$s) = $self->_def_time($h,$mn,$s,$noupdate);
1816 1124 ▶ $h24 = 1 if ($h == 24 && $mn == 0 && $s == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $h == 24 and $mn == 0 and $s == 0 1 1123 1124
Condition66%4/6
$h == 24 and $mn == 0 and $s == 0
!ll&&!rl&&r
112301
$h == 24 and $mn == 0
!ll&&!rl&&r
112301
MC/DC33%1/3
$h == 24 and $mn == 0 and $s == 0
$h == 24 $mn == 0 $s == 0
Truth table50%2/4
A and B and C
A= $h == 24B= $mn == 0C= $s == 0
ABCresult
0XX0
10X0
1100
1111
1817 1124 $string =~ s/\s*$//;
1818 1124 $got_time = 1;
1819 }
1820 }
1821  
1822 # If we called this from $date->parse()
1823 # returns the string and a list of time components
1824  
1825 2009 ▶ if ($caller eq 'parse') {
Branch: 1 branch
BranchTrueFalseTotal
if ($caller eq "parse") 1979 30 2009
1826 1979 ▶ if ($got_time) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got_time) { } 1108 871 1979
1827 1108 ($h,$mn,$s) = $self->_time($h,$mn,$s,$fh,$fm,$h24,$ampm,$noupdate);
1828 1108 return ($got_time,$string,$h,$mn,$s,$tzstring,$zone,$abb,$off);
1829 } else {
1830 871 return (0);
1831 }
1832 }
1833  
1834 # If we called this from $date->parse_time()
1835  
1836 30 ▶ if (! $got_time || $string) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $got_time or $string) 5 25 30
Condition66%2/3
not $got_time or $string
l!l&&r!l&&!r
0525
MC/DC50%1/2
not $got_time or $string
not $got_time $string
Truth table66%2/3
not(A) or B
A= not $got_timeB= $string
ABresult
1X1
011
000
1837 5 $$self{'err'} = "[$caller] Invalid time string";
1838 5 return ();
1839 }
1840  
1841 25 ($h,$mn,$s) = $self->_time($h,$mn,$s,$fh,$fm,$h24,$ampm,$noupdate);
1842 25 return ($h,$mn,$s,$tzstring,$zone,$abb,$off);
1843 }
1844  
1845 # Parse common dates
1846 2915 ▶sub _parse_date_common {
Subroutine _parse_date_common: called CC=8 SCAR=20.8
1847 2915 my($self,$string,$noupdate) = @_;
1848 2915 my $dmt = $$self{'tz'};
1849 2915 my $dmb = $$dmt{'base'};
1850  
1851 # Since we want whitespace to be used as a separator, turn all
1852 # whitespace into single spaces. This is necessary since the
1853 # regexps do backreferences to make sure that separators are
1854 # not mixed.
1855 2915 $string =~ s/\s+/ /g;
1856  
1857 my $daterx = (exists $$dmb{'data'}{'rx'}{'other'}{'common_1'} ?
1858 2915 ▶ $$dmb{'data'}{'rx'}{'other'}{'common_1'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $dmb->{'data'}{'rx'}{'other'}{'common_1'} ? : 2842 73 2915
1859 $self->_other_rx('common_1'));
1860  
1861 2915 ▶ if ($string =~ $daterx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$daterx/) 228 2687 2915
1862 228 my($y,$m,$d) = @+{qw(y m d)};
1863  
1864 228 ▶ if ($dmb->_config('dateformat') ne 'US') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dmb->_config("dateformat") ne "US") 20 208 228
1865 20 ($m,$d) = ($d,$m);
1866 }
1867  
1868 228 ($y,$m,$d) = $self->_def_date($y,$m,$d,$noupdate);
1869 228 return($y,$m,$d);
1870 }
1871  
1872 $daterx = (exists $$dmb{'data'}{'rx'}{'other'}{'common_2'} ?
1873 2687 ▶ $$dmb{'data'}{'rx'}{'other'}{'common_2'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $dmb->{'data'}{'rx'}{'other'}{'common_2'} ? : 2614 73 2687
1874 $self->_other_rx('common_2'));
1875  
1876 2687 ▶ if ($string =~ $daterx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$daterx/) 1358 1329 2687
1877 1358 my($y,$m,$d,$mmm,$month) = @+{qw(y m d mmm month)};
1878  
1879 1358 ▶ if ($mmm) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mmm) { } 1237 121 1358
elsif ($month) { } 115 6 121
1880 1237 $m = $$dmb{'data'}{'wordmatch'}{'month_abb'}{lc($mmm)};
1881 } elsif ($month) {
1882 115 $m = $$dmb{'data'}{'wordmatch'}{'month_name'}{lc($month)};
1883 }
1884  
1885 1358 ($y,$m,$d) = $self->_def_date($y,$m,$d,$noupdate);
1886 1358 return($y,$m,$d);
1887 }
1888  
1889 1329 return ();
1890 }
1891  
1892 # Parse truncated dates
1893 420 ▶sub _parse_date_truncated {
Subroutine _parse_date_truncated: called CC=9 SCAR=22.9
1894 420 my($self,$string,$noupdate) = @_;
1895 420 my $dmt = $$self{'tz'};
1896 420 my $dmb = $$dmt{'base'};
1897  
1898 my $daterx = (exists $$dmb{'data'}{'rx'}{'other'}{'truncated'} ?
1899 420 ▶ $$dmb{'data'}{'rx'}{'other'}{'truncated'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $dmb->{'data'}{'rx'}{'other'}{'truncated'} ? : 385 35 420
1900 $self->_other_rx('truncated'));
1901  
1902 420 ▶ return () if (! $daterx);
Branch: 1 branch
BranchTrueFalseTotal
unless $daterx 404 16 420
1903  
1904 # Since we want whitespace to be used as a separator, turn all
1905 # whitespace into single spaces. This is necessary since the
1906 # regexps do backreferences to make sure that separators are
1907 # not mixed.
1908 16 $string =~ s/\s+/ /g;
1909  
1910 16 ▶ if ($string =~ $daterx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$daterx/) 16 0 16
1911 16 my($y,$mmm,$month) = @+{qw(y mmm month)};
1912  
1913 16 my ($m,$d);
1914 16 ▶ if ($mmm) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mmm) { } 16 0 16
elsif ($month) { } 0 0 0
1915 16 $m = $$dmb{'data'}{'wordmatch'}{'month_abb'}{lc($mmm)};
1916 } elsif ($month) {
1917 0 $m = $$dmb{'data'}{'wordmatch'}{'month_name'}{lc($month)};
1918 }
1919  
1920 # Handle all of the mmmYYYY formats
1921  
1922 16 ▶ if ($y && $m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y and $m) 16 0 16
Condition33%1/3
$y and $m
!ll&&!rl&&r
0016
MC/DC0%0/2
$y and $m
$y $m
Truth table33%1/3
A and B
A= $yB= $m
ABresult
0X0
100
111
1923  
1924 16 my $format_mmmyyyy = $dmb->_config('format_mmmyyyy');
1925 16 ▶ if ($format_mmmyyyy eq 'first') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format_mmmyyyy eq 'first') { } 8 8 16
1926 8 $d=1;
1927 8 $$self{'data'}{'default_time'} = [0,0,0];
1928 } else {
1929 8 $d=$dmb->days_in_month($y,$m);
1930 8 $$self{'data'}{'default_time'} = [23,59,59];
1931 }
1932  
1933 16 $$self{'data'}{'def'}[0] = '';
1934 16 $$self{'data'}{'def'}[1] = '';
1935 16 $$self{'data'}{'def'}[2] = 1;
1936 16 return($y,$m,$d);
1937 }
1938 }
1939  
1940 0 return ();
1941 }
1942  
1943 281 ▶sub _parse_tz {
Subroutine _parse_tz: called CC=2 SCAR=6.9
1944 281 my($self,$string,$noupdate) = @_;
1945 281 my $dmt = $$self{'tz'};
1946 281 my($tzstring,$zone,$abb,$off);
1947  
1948 281 my $rx = $dmt->_zrx('zrx');
1949 281 ▶ if ($string =~ s/(?:^|\s)$rx(?:$|\s)/ /) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/(?:^|\s)$rx(?:$|\s)/ /) 9 272 281
1950 9 ($tzstring,$zone,$abb,$off) = @+{qw(tzstring zone abb off)};
1951 9 return($string,$tzstring,$zone,$abb,$off);
1952 }
1953 272 return($string);
1954 }
1955  
1956 2911 ▶sub _parse_dow {
Subroutine _parse_dow: called CC=7 SCAR=19.5
1957 2911 my($self,$string,$noupdate) = @_;
1958 2911 my $dmt = $$self{'tz'};
1959 2911 my $dmb = $$dmt{'base'};
1960 2911 my($y,$m,$d,$dow);
1961  
1962 # Remove the day of week
1963  
1964 my $rx = (exists $$dmb{'data'}{'rx'}{'other'}{'dow'} ?
1965 2911 ▶ $$dmb{'data'}{'rx'}{'other'}{'dow'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $dmb->{'data'}{'rx'}{'other'}{'dow'} ? : 2838 73 2911
1966 $self->_other_rx('dow'));
1967 2911 ▶ if ($string =~ s/$rx/ /) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ s/$rx/ /) { } 1261 1650 2911
1968 1261 $dow = $+{'dow'};
1969 1261 $dow = lc($dow);
1970  
1971 $dow = $$dmb{'data'}{'wordmatch'}{'day_abb'}{$dow}
1972 1261 ▶ if (exists $$dmb{'data'}{'wordmatch'}{'day_abb'}{$dow});
Branch: 1 branch
BranchTrueFalseTotal
if exists $dmb->{"data"}{"wordmatch"}{"day_abb"}{$dow} 567 694 1261
1973 $dow = $$dmb{'data'}{'wordmatch'}{'day_name'}{$dow}
1974 1261 ▶ if (exists $$dmb{'data'}{'wordmatch'}{'day_name'}{$dow});
Branch: 1 branch
BranchTrueFalseTotal
if exists $dmb->{"data"}{"wordmatch"}{"day_name"}{$dow} 694 567 1261
1975 } else {
1976 1650 return (0);
1977 }
1978  
1979 1261 $string =~ s/\s*$//;
1980 1261 $string =~ s/^\s*//;
1981  
1982 1261 ▶ return (0,$string,$dow) if ($string);
Branch: 1 branch
BranchTrueFalseTotal
if $string 1243 18 1261
1983  
1984 # Handle the simple DoW format
1985  
1986 18 ($y,$m,$d) = $self->_def_date($y,$m,$d,$noupdate);
1987  
1988 18 my($w,$dow1);
1989  
1990 18 ($y,$w) = $dmb->week_of_year([$y,$m,$d]); # week of year
1991 18 ($y,$m,$d) = @{ $dmb->week_of_year($y,$w) }; # first day
1992 18 $dow1 = $dmb->day_of_week([$y,$m,$d]); # DoW of first day
1993 18 ▶ $dow1 -= 7 if ($dow1 > $dow);
Branch: 1 branch
BranchTrueFalseTotal
if $dow1 > $dow 0 18 18
1994 18 ($y,$m,$d) = @{ $dmb->calc_date_days([$y,$m,$d],$dow-$dow1) };
1995  
1996 18 return(1,$y,$m,$d);
1997 }
1998  
1999 257 ▶sub _parse_holidays {
Subroutine _parse_holidays: called CC=5 SCAR=16.1
2000 257 my($self,$string,$noupdate) = @_;
2001 257 my $dmt = $$self{'tz'};
2002 257 my $dmb = $$dmt{'base'};
2003 257 my($y,$m,$d);
2004  
2005 257 ▶ if (! exists $$dmb{'data'}{'rx'}{'holidays'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $dmb->{"data"}{"rx"}{"holidays"}) 150 107 257
2006 150 return (0);
2007 }
2008  
2009 107 $string =~ s/\s*$//;
2010 107 $string =~ s/^\s*//;
2011  
2012 107 my $rx = $$dmb{'data'}{'rx'}{'holidays'};
2013 107 ▶ if ($string =~ $rx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$rx/) 9 98 107
2014 9 my $hol;
2015 9 ($y,$hol) = @+{qw(y holiday)};
2016 9 ▶ $y = $dmt->_now('y',$noupdate) if (! $y);
Branch: 1 branch
BranchTrueFalseTotal
unless $y 5 4 9
2017 9 $y += 0;
2018  
2019 9 $self->_holidays($y-1);
2020 9 $self->_holidays($y);
2021 9 $self->_holidays($y+1);
2022 9 ▶ return (0) if (! exists $$dmb{'data'}{'holidays'}{'yhols'}{$y+0}{$hol});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $dmb->{"data"}{"holidays"}{"yhols"}{$y + 0}{$hol} 0 9 9
2023 9 my ($y,$m,$d) = @{ $$dmb{'data'}{'holidays'}{'yhols'}{$y+0}{$hol} };
2024 9 return(1,$y,$m,$d);
2025 }
2026  
2027 98 return (0);
2028 }
2029  
2030 170 ▶no integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
2031 334 ▶sub _parse_delta {
Subroutine _parse_delta: called CC=21 SCAR=34.8
2032 334 my($self,$string,$dow,$got_time,$h,$mn,$s,$noupdate) = @_;
2033 334 my $dmt = $$self{'tz'};
2034 334 my $dmb = $$dmt{'base'};
2035 334 my($y,$m,$d);
2036  
2037 334 my $delta = $self->new_delta();
2038 334 my $err = $delta->parse($string);
2039 334 my $tz = $dmt->_now('tz');
2040 334 my $isdst = $dmt->_now('isdst');
2041  
2042 334 ▶ if (! $err) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 36 298 334
2043 36 my($dy,$dm,$dw,$dd,$dh,$dmn,$ds) = @{ $$delta{'data'}{'delta'} };
2044  
2045 # We can't handle a delta longer than 10000 years
2046 36 ▶ if (abs($dy) > 10000 ||
Branch: 1 branch
BranchTrueFalseTotal
if (abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000 or abs $dd > 3660000 or abs $dh > 87840000 or abs $dmn > 5270400000 or abs $ds > '316224000000') 0 36 36
Condition33%6/18
abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000 or abs $dd > 3660000 or abs $dh > 87840000 or abs $dmn > 5270400000 or abs $ds > '316224000000'
l!l&&r!l&&!r
0036
abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000 or abs $dd > 3660000 or abs $dh > 87840000 or abs $dmn > 5270400000
l!l&&r!l&&!r
0036
abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000 or abs $dd > 3660000 or abs $dh > 87840000
l!l&&r!l&&!r
0036
abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000 or abs $dd > 3660000
l!l&&r!l&&!r
0036
abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000
l!l&&r!l&&!r
0036
abs $dy > 10000 or abs $dm > 120000
l!l&&r!l&&!r
0036
MC/DC0%0/7
abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000 or abs $dd > 3660000 or abs $dh > 87840000 or abs $dmn > 5270400000 or abs $ds > '316224000000'
abs $dy > 10000 abs $dm > 120000 abs $dw > 530000 abs $dd > 3660000 abs $dh > 87840000 abs $dmn > 5270400000 abs $ds > '316224000000'
Truth table12%1/8
A or B or C or D or E or F or G
A= abs $dy > 10000B= abs $dm > 120000C= abs $dw > 530000D= abs $dd > 3660000E= abs $dh > 87840000F= abs $dmn > 5270400000G= abs $ds > '316224000000'
ABCDEFGresult
1XXXXXX1
01XXXXX1
001XXXX1
0001XXX1
00001XX1
000001X1
00000011
00000000
2047 abs($dm) > 120000 || # 10000*12
2048 abs($dw) > 530000 || # 10000*53
2049 abs($dd) > 3660000 || # 10000*366
2050 abs($dh) > 87840000 || # 10000*366*24
2051 abs($dmn) > 5270400000 || # 10000*366*24*60
2052 abs($ds) > 316224000000) { # 10000*366*24*60*60
2053 0 $$self{'err'} = '[parse] Delta too large';
2054 0 return (1);
2055 }
2056  
2057 36 ▶ if ($got_time &&
Branch: 1 branch
BranchTrueFalseTotal
if ($got_time and $dh != 0 || $dmn != 0 || $ds != 0) 6 30 36
Condition88%8/9
$got_time and $dh != 0 || $dmn != 0 || $ds != 0
!ll&&!rl&&r
2466
$dh != 0 or $dmn != 0 or $ds != 0
l!l&&r!l&&!r
606
$dh != 0 or $dmn != 0
l!l&&r!l&&!r
246
MC/DC75%3/4
$got_time and $dh != 0 || $dmn != 0 || $ds != 0
$got_time $dh != 0 $dmn != 0 $ds != 0
Truth table80%4/5
A and B or C or D
A= $got_timeB= $dh != 0C= $dmn != 0D= $ds != 0
ABCDresult
0XXX0
10000
11XX1
101X1
10011
2058 ($dh != 0 || $dmn != 0 || $ds != 0)) {
2059 6 $$self{'err'} = '[parse] Two times entered or implied';
2060 6 return (1);
2061 }
2062  
2063 30 ▶ if ($got_time) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got_time) { } 6 24 30
2064 6 ($y,$m,$d) = $self->_def_date($y,$m,$d,$noupdate);
2065 } else {
2066 24 ($y,$m,$d,$h,$mn,$s) = $dmt->_now('now',$$noupdate);
2067 24 $$noupdate = 1;
2068 }
2069  
2070 30 ▶ my $business = ($$delta{'data'}{'mode'} eq 'business' ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$delta->{'data'}{'mode'} eq 'business' ? : 0 30 30
2071  
2072 30 my($date2,$offset,$abbrev);
2073 30 ($err,$date2,$offset,$isdst,$abbrev) =
2074 $self->__calc_date_delta([$y,$m,$d,$h,$mn,$s],
2075 [$dy,$dm,$dw,$dd,$dh,$dmn,$ds],
2076 0,$business,$tz,$isdst);
2077 30 ($y,$m,$d,$h,$mn,$s) = @$date2;
2078  
2079 30 ▶ if ($dow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dow) 10 20 30
2080 10 ▶ if ($dd != 0 || $dh != 0 || $dmn != 0 || $ds != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dd != 0 or $dh != 0 or $dmn != 0 or $ds != 0) 0 10 10
Condition33%3/9
$dd != 0 or $dh != 0 or $dmn != 0 or $ds != 0
l!l&&r!l&&!r
0010
$dd != 0 or $dh != 0 or $dmn != 0
l!l&&r!l&&!r
0010
$dd != 0 or $dh != 0
l!l&&r!l&&!r
0010
MC/DC0%0/4
$dd != 0 or $dh != 0 or $dmn != 0 or $ds != 0
$dd != 0 $dh != 0 $dmn != 0 $ds != 0
Truth table20%1/5
A or B or C or D
A= $dd != 0B= $dh != 0C= $dmn != 0D= $ds != 0
ABCDresult
1XXX1
01XX1
001X1
00011
00000
2081 0 $$self{'err'} = '[parse] Day of week not allowed';
2082 0 return (1);
2083 }
2084  
2085 10 my($w,$dow1);
2086  
2087 10 ($y,$w) = $dmb->week_of_year([$y,$m,$d]); # week of year
2088 10 ($y,$m,$d) = @{ $dmb->week_of_year($y,$w) }; # first day
2089 10 $dow1 = $dmb->day_of_week([$y,$m,$d]); # DoW of first day
2090 10 ▶ $dow1 -= 7 if ($dow1 > $dow);
Branch: 1 branch
BranchTrueFalseTotal
if $dow1 > $dow 0 10 10
2091 10 ($y,$m,$d) = @{ $dmb->calc_date_days([$y,$m,$d],$dow-$dow1) };
2092 }
2093  
2094 30 return (1,$y,$m,$d,$h,$mn,$s);
2095 }
2096  
2097 298 return (0);
2098 }
2099 170 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
2100  
2101 2003 ▶sub _parse_datetime_other {
Subroutine _parse_datetime_other: called CC=25 SCAR=36.3
2102 2003 my($self,$string,$noupdate) = @_;
2103 2003 my $dmt = $$self{'tz'};
2104 2003 my $dmb = $$dmt{'base'};
2105  
2106 my $rx = (exists $$dmb{'data'}{'rx'}{'other'}{'miscdatetime'} ?
2107 2003 ▶ $$dmb{'data'}{'rx'}{'other'}{'miscdatetime'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $dmb->{'data'}{'rx'}{'other'}{'miscdatetime'} ? : 1938 65 2003
2108 $self->_other_rx('miscdatetime'));
2109  
2110 2003 ▶ if ($string =~ $rx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$rx/) 24 1979 2003
2111 my ($special,$epoch,$y,$mmm,$d,$h,$mn,$s,$tzstring,$zone,$abb,$off) =
2112 24 @+{qw(special epoch y mmm d h mn s tzstring zone abb off)};
2113  
2114 24 ▶ if (defined($special)) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $special) { } 18 6 24
elsif (defined $epoch) { } 5 1 6
elsif (defined $y) { } 1 0 1
2115 18 my $delta = $$dmb{'data'}{'wordmatch'}{'offset_time'}{lc($special)};
2116 18 my @delta = @{ $dmb->split('delta',$delta) };
2117 18 my @date = $dmt->_now('now',$$noupdate);
2118 18 my $tz = $dmt->_now('tz');
2119 18 my $isdst = $dmt->_now('isdst');
2120 18 $$noupdate = 1;
2121  
2122 18 my($err,$date2,$offset,$abbrev);
2123 18 ($err,$date2,$offset,$isdst,$abbrev) =
2124 $self->__calc_date_delta([@date],[@delta],0,0,$tz,$isdst);
2125  
2126 18 ▶ if ($tzstring) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tzstring) 1 17 18
2127  
2128 1 ▶ $date2 = [] if (! defined $date2);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date2 0 1 1
2129 1 ▶ my $offset = (defined $off ? $dmb->_delta_convert('offset',$off) : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $off ? : 0 1 1
2130 1 ▶ $zone = (defined $zone ? lc($zone) : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $zone ? : 0 1 1
2131 1 ▶ my $abbrev = (defined $abb ? lc($abb) : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $abb ? : 1 0 1
2132  
2133 # In some cases, a valid abbreviation is also a valid timezone
2134 1 my $tmp = $dmt->__zone($date2,$offset,$zone,$abbrev,'');
2135 1 ▶ if (! $tmp && $abbrev && ! $zone) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $tmp and $abbrev and not $zone) 0 1 1
Condition33%2/6
not $tmp and $abbrev and not $zone
!ll&&!rl&&r
100
not $tmp and $abbrev
!ll&&!rl&&r
100
MC/DC0%0/3
not $tmp and $abbrev and not $zone
not $tmp $abbrev not $zone
Truth table25%1/4
not(A) and B and not(C)
A= not $tmpB= $abbrevC= not $zone
ABCresult
0XX0
10X0
1100
1111
2136 0 $abbrev = $dmt->_zone($abbrev);
2137 0 ▶ $tmp = $dmt->__zone($date2,$offset,$abbrev,'','') if ($abbrev);
Branch: 1 branch
BranchTrueFalseTotal
if $abbrev 0 0 0
2138 }
2139 1 $zone = $tmp;
2140  
2141 1 ▶ return (0) if (! $zone);
Branch: 1 branch
BranchTrueFalseTotal
unless $zone 0 1 1
2142  
2143 1 my(@tmp) = $dmt->_convert('_parse_datetime_other',$date2,$tz,$zone);
2144 1 $date2 = $tmp[1];
2145 }
2146  
2147 18 @date = @$date2;
2148  
2149 18 return (1,@date,$tzstring,$zone,$abb,$off);
2150  
2151 } elsif (defined($epoch)) {
2152 5 my $date = [1970,1,1,0,0,0];
2153 5 my @delta = (0,0,$epoch);
2154 5 $date = $dmb->calc_date_time($date,\@delta);
2155 5 my($err);
2156 5 ▶ if ($tzstring) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tzstring) { } 1 4 5
2157  
2158 1 ▶ my $offset = (defined $off ? $dmb->_delta_convert('offset',$off) : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $off ? : 0 1 1
2159 1 ▶ $zone = (defined $zone ? lc($zone) : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $zone ? : 0 1 1
2160 1 ▶ my $abbrev = (defined $abb ? lc($abb) : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $abb ? : 1 0 1
2161  
2162 # In some cases, a valid abbreviation is also a valid timezone
2163 1 my $tmp = $dmt->__zone($date,$offset,$zone,$abbrev,'');
2164 1 ▶ if (! $tmp && $abbrev && ! $zone) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $tmp and $abbrev and not $zone) 0 1 1
Condition33%2/6
not $tmp and $abbrev and not $zone
!ll&&!rl&&r
100
not $tmp and $abbrev
!ll&&!rl&&r
100
MC/DC0%0/3
not $tmp and $abbrev and not $zone
not $tmp $abbrev not $zone
Truth table25%1/4
not(A) and B and not(C)
A= not $tmpB= $abbrevC= not $zone
ABCresult
0XX0
10X0
1100
1111
2165 0 $abbrev = $dmt->_zone($abbrev);
2166 0 ▶ $tmp = $dmt->__zone($date,$offset,$abbrev,'','') if ($abbrev);
Branch: 1 branch
BranchTrueFalseTotal
if $abbrev 0 0 0
2167 }
2168 1 $zone = $tmp;
2169  
2170 1 ▶ return (0) if (! $zone);
Branch: 1 branch
BranchTrueFalseTotal
unless $zone 0 1 1
2171  
2172 1 ($err,$date) = $dmt->convert_from_gmt($date,$zone);
2173 } else {
2174 4 ($err,$date) = $dmt->convert_from_gmt($date);
2175 }
2176 5 return (1,@$date,$tzstring,$zone,$abb,$off);
2177  
2178 } elsif (defined($y)) {
2179 1 my $m = $$dmb{'data'}{'wordmatch'}{'month_abb'}{lc($mmm)};
2180 1 return (1,$y,$m,$d,$h,$mn,$s,$tzstring,$zone,$abb,$off);
2181 }
2182 }
2183  
2184 1979 return (0);
2185 }
2186  
2187 1329 ▶sub _parse_date_other {
Subroutine _parse_date_other: called CC=49 SCAR=39.1
2188 1329 my($self,$string,$dow,$of,$noupdate) = @_;
2189 1329 my $dmt = $$self{'tz'};
2190 1329 my $dmb = $$dmt{'base'};
2191 1329 my($y,$m,$d,$h,$mn,$s);
2192  
2193 my $rx = (exists $$dmb{'data'}{'rx'}{'other'}{'misc'} ?
2194 1329 ▶ $$dmb{'data'}{'rx'}{'other'}{'misc'} :
Branch: 1 branch
BranchTrueFalseTotal
exists $dmb->{'data'}{'rx'}{'other'}{'misc'} ? : 1283 46 1329
2195 $self->_other_rx('misc'));
2196  
2197 1329 my($mmm,$month,$nextprev,$last,$field_y,$field_m,$field_w,$field_d,$nth);
2198 1329 my($special,$got_m,$n,$got_y);
2199  
2200 1329 ▶ if ($string =~ $rx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$rx/) { } 879 450 1329
2201 ($y,$mmm,$month,$nextprev,$last,$field_y,$field_m,$field_w,$field_d,$nth,
2202 $special,$n) =
2203 879 @+{qw(y mmm month next last field_y field_m field_w field_d
2204 nth special n)};
2205  
2206 879 ▶ if (defined($y)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $y) { } 90 789 879
2207 90 $y = $dmt->_fix_year($y);
2208 90 $got_y = 1;
2209 90 ▶ return () if (! $y);
Branch: 1 branch
BranchTrueFalseTotal
unless $y 0 90 90
2210 } else {
2211 789 $y = $dmt->_now('y',$$noupdate);
2212 789 $$noupdate = 1;
2213 789 $got_y = 0;
2214 789 $$self{'data'}{'def'}[0] = '';
2215 }
2216  
2217 879 ▶ if (defined($mmm)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $mmm) { } 698 181 879
elsif ($month) { } 31 150 181
2218 698 $m = $$dmb{'data'}{'wordmatch'}{'month_abb'}{lc($mmm)};
2219 698 $got_m = 1;
2220 } elsif ($month) {
2221 31 $m = $$dmb{'data'}{'wordmatch'}{'month_name'}{lc($month)};
2222 31 $got_m = 1;
2223 }
2224  
2225 879 ▶ if ($nth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nth) 632 247 879
2226 632 $nth = $$dmb{'data'}{'wordmatch'}{'nth'}{lc($nth)};
2227 }
2228  
2229 879 ▶ if ($got_m && $nth && ! $dow) {
Branch: 7 branches
BranchTrueFalseTotal
if ($got_m and $nth and not $dow) { } 32 847 879
elsif ($nextprev) { } 50 797 847
elsif ($last) { } 127 670 797
elsif ($nth and $dow and not $field_w) { } 584 86 670
elsif ($field_w and $dow) { } 25 61 86
elsif ($nth and not $got_y) { } 5 56 61
elsif ($special) { } 56 0 56
Condition100%6/6
$got_m and $nth and not $dow
!ll&&!rl&&r
27657132
$got_m and $nth
!ll&&!rl&&r
150126603
MC/DC100%3/3
$got_m and $nth and not $dow
$got_m $nth not $dow
Truth table100%4/4
A and B and not(C)
A= $got_mB= $nthC= not $dow
ABCresult
0XX0
10X0
1100
1111
2230 # Dec 1st 1970
2231 # 1st Dec 1970
2232 # 1970 Dec 1st
2233 # 1970 1st Dec
2234  
2235 32 $d = $nth;
2236  
2237 } elsif ($nextprev) {
2238  
2239 50 my $next = 0;
2240 50 my $sign = -1;
2241 50 ▶ if ($$dmb{'data'}{'wordmatch'}{'nextprev'}{lc($nextprev)} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dmb->{"data"}{"wordmatch"}{"nextprev"}{lc $nextprev} == 1) 22 28 50
2242 22 $next = 1;
2243 22 $sign = 1;
2244 }
2245  
2246 50 ▶ if ($field_y || $field_m || $field_w) {
Branch: 2 branches
BranchTrueFalseTotal
if ($field_y or $field_m or $field_w) { } 28 22 50
elsif ($dow) { } 22 0 22
Condition100%6/6
$field_y or $field_m or $field_w
l!l&&r!l&&!r
181022
$field_y or $field_m
l!l&&r!l&&!r
81032
MC/DC100%3/3
$field_y or $field_m or $field_w
$field_y $field_m $field_w
Truth table100%4/4
A or B or C
A= $field_yB= $field_mC= $field_w
ABCresult
1XX1
01X1
0011
0000
2247 # next/prev year/month/week
2248  
2249 28 my(@delta);
2250 28 ▶ if ($field_y) {
Branch: 2 branches
BranchTrueFalseTotal
if ($field_y) { } 8 20 28
elsif ($field_m) { } 10 10 20
2251 8 @delta = ($sign*1,0,0,0,0,0,0);
2252 } elsif ($field_m) {
2253 10 @delta = (0,$sign*1,0,0,0,0,0);
2254 } else {
2255 10 @delta = (0,0,$sign*1,0,0,0,0);
2256 }
2257  
2258 28 my @now = $dmt->_now('now',$$noupdate);
2259 28 my $tz = $dmt->_now('tz');
2260 28 my $isdst = $dmt->_now('isdst');
2261 28 $$noupdate = 1;
2262  
2263 28 my($err,$offset,$abbrev,$date2);
2264 28 ($err,$date2,$offset,$isdst,$abbrev) =
2265 $self->__calc_date_delta([@now],[@delta],0,0,$tz,$isdst);
2266 28 ($y,$m,$d,$h,$mn,$s) = @$date2;
2267  
2268 } elsif ($dow) {
2269 # next/prev friday
2270  
2271 22 my @now = $dmt->_now('now',$$noupdate);
2272 22 $$noupdate = 1;
2273 22 ($y,$m,$d,$h,$mn,$s) = @{ $self->__next_prev(\@now,$next,$dow,0) };
2274 22 $dow = 0;
2275  
2276 } else {
2277 0 return ();
2278 }
2279  
2280 } elsif ($last) {
2281  
2282 127 ▶ if ($field_d && $got_m) {
Branch: 3 branches
BranchTrueFalseTotal
if ($field_d and $got_m) { } 6 121 127
elsif ($dow and $got_m) { } 120 1 121
elsif ($dow) { } 1 0 1
Condition66%2/3
$field_d and $got_m
!ll&&!rl&&r
12106
MC/DC50%1/2
$field_d and $got_m
$field_d $got_m
Truth table66%2/3
A and B
A= $field_dB= $got_m
ABresult
0X0
100
111
2283 # last day in october 95
2284  
2285 6 $d = $dmb->days_in_month($y,$m);
2286  
2287 ▶ } elsif ($dow && $got_m) {
Condition66%2/3
$dow and $got_m
!ll&&!rl&&r
01120
MC/DC50%1/2
$dow and $got_m
$dow $got_m
Truth table66%2/3
A and B
A= $dowB= $got_m
ABresult
0X0
100
111
2288 # last friday in october 95
2289  
2290 120 $d = $dmb->days_in_month($y,$m);
2291 ($y,$m,$d,$h,$mn,$s) =
2292 120 @{ $self->__next_prev([$y,$m,$d,0,0,0],0,$dow,1) };
2293 120 $dow = 0;
2294  
2295 } elsif ($dow) {
2296 # last friday in 95
2297  
2298 ($y,$m,$d,$h,$mn,$s) =
2299 1 @{ $self->__next_prev([$y,12,31,0,0,0],0,$dow,0) };
2300  
2301 } else {
2302 0 return ();
2303 }
2304  
2305 ▶ } elsif ($nth && $dow && ! $field_w) {
Condition100%6/6
$nth and $dow and not $field_w
!ll&&!rl&&r
7511584
$nth and $dow
!ll&&!rl&&r
705595
MC/DC100%3/3
$nth and $dow and not $field_w
$nth $dow not $field_w
Truth table100%4/4
A and B and not(C)
A= $nthB= $dowC= not $field_w
ABCresult
0XX0
10X0
1100
1111
2306  
2307 584 ▶ if ($got_m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got_m) { } 571 13 584
2308 571 ▶ if ($of) {
Branch: 1 branch
BranchTrueFalseTotal
if ($of) { } 569 2 571
2309 # nth DoW of MMM [YYYY]
2310 569 ▶ return () if ($nth > 5);
Branch: 1 branch
BranchTrueFalseTotal
if $nth > 5 2 567 569
2311  
2312 567 $d = 1;
2313 ($y,$m,$d,$h,$mn,$s) =
2314 567 @{ $self->__next_prev([$y,$m,1,0,0,0],1,$dow,1) };
2315 567 my $m2 = $m;
2316 567 ▶ ($y,$m2,$d) = @{ $dmb->calc_date_days([$y,$m,$d],7*($nth-1)) }
Branch: 1 branch
BranchTrueFalseTotal
if $nth > 1 454 113 567
2317 if ($nth > 1);
2318 567 ▶ return () if (! $m2 || $m2 != $m);
Branch: 1 branch
BranchTrueFalseTotal
if not $m2 or $m2 != $m 0 567 567
Condition33%1/3
not $m2 or $m2 != $m
l!l&&r!l&&!r
00567
MC/DC0%0/2
not $m2 or $m2 != $m
not $m2 $m2 != $m
Truth table33%1/3
not(A) or B
A= not $m2B= $m2 != $m
ABresult
1X1
011
000
2319  
2320 } else {
2321 # DoW, nth MMM [YYYY] (i.e. Sunday, 9th Dec 2008)
2322 2 $d = $nth;
2323 }
2324  
2325 } else {
2326 # nth DoW [in YYYY]
2327  
2328 13 ($y,$m,$d,$h,$mn,$s) = @{ $self->__next_prev([$y,1,1,0,0,0],1,$dow,1) };
2329 13 ▶ ($y,$m,$d) = @{ $dmb->calc_date_days([$y,$m,$d],7*($nth-1)) }
Branch: 1 branch
BranchTrueFalseTotal
if $nth > 1 9 4 13
2330 if ($nth > 1);
2331 }
2332  
2333 ▶ } elsif ($field_w && $dow) {
Condition100%3/3
$field_w and $dow
!ll&&!rl&&r
52925
MC/DC100%2/2
$field_w and $dow
$field_w $dow
Truth table100%3/3
A and B
A= $field_wB= $dow
ABresult
0X0
100
111
2334  
2335 25 ▶ if (defined($n) || $nth) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n or $nth) { } 23 2 25
Condition100%3/3
defined $n or $nth
l!l&&r!l&&!r
12112
MC/DC100%2/2
defined $n or $nth
defined $n $nth
Truth table100%3/3
A or B
A= defined $nB= $nth
ABresult
1X1
011
000
2336 # sunday week 22 in 1996
2337 # sunday 22nd week in 1996
2338  
2339 23 ▶ $n = $nth if ($nth);
Branch: 1 branch
BranchTrueFalseTotal
if $nth 11 12 23
2340 23 ▶ return () if (! $n);
Branch: 1 branch
BranchTrueFalseTotal
unless $n 2 21 23
2341 21 ($y,$m,$d) = @{ $dmb->week_of_year($y,$n) };
2342 21 ($y,$m,$d) = @{ $self->__next_prev([$y,$m,$d,0,0,0],1,$dow,1) };
2343  
2344 } else {
2345 # DoW week
2346  
2347 2 ($y,$m,$d) = $dmt->_now('now',$$noupdate);
2348 2 $$noupdate = 1;
2349 2 my $tmp = $dmb->_config('firstday');
2350 2 ($y,$m,$d) = @{ $self->__next_prev([$y,$m,$d,0,0,0],1,$tmp,0) };
2351 2 ($y,$m,$d) = @{ $self->__next_prev([$y,$m,$d,0,0,0],1,$dow,1) };
2352 }
2353  
2354 ▶ } elsif ($nth && ! $got_y) {
Condition66%2/3
$nth and not $got_y
!ll&&!rl&&r
5605
MC/DC50%1/2
$nth and not $got_y
$nth not $got_y
Truth table66%2/3
A and not(B)
A= $nthB= not $got_y
ABresult
0X0
100
111
2355 # 'in one week' makes it here too so return nothing in that case so it
2356 # drops through to the deltas.
2357 5 ▶ return () if ($field_d || $field_w || $field_m || $field_y);
Branch: 1 branch
BranchTrueFalseTotal
if $field_d or $field_w or $field_m or $field_y 1 4 5
Condition66%6/9
$field_d or $field_w or $field_m or $field_y
l!l&&r!l&&!r
104
$field_d or $field_w or $field_m
l!l&&r!l&&!r
104
$field_d or $field_w
l!l&&r!l&&!r
014
MC/DC25%1/4
$field_d or $field_w or $field_m or $field_y
$field_d $field_w $field_m $field_y
Truth table40%2/5
A or B or C or D
A= $field_dB= $field_wC= $field_mD= $field_y
ABCDresult
1XXX1
01XX1
001X1
00011
00000
2358 4 ($y,$m,$d) = $dmt->_now('now',$$noupdate);
2359 4 $$noupdate = 1;
2360 4 $d = $nth;
2361  
2362 } elsif ($special) {
2363  
2364 56 my $delta = $$dmb{'data'}{'wordmatch'}{'offset_date'}{lc($special)};
2365 56 my @delta = @{ $dmb->split('delta',$delta) };
2366 56 ($y,$m,$d) = $dmt->_now('now',$$noupdate);
2367 56 my $tz = $dmt->_now('tz');
2368 56 my $isdst = $dmt->_now('isdst');
2369 56 $$noupdate = 1;
2370 56 my($err,$offset,$abbrev,$date2);
2371 56 ($err,$date2,$offset,$isdst,$abbrev) =
2372 $self->__calc_date_delta([$y,$m,$d,0,0,0],[@delta],0,0,$tz,$isdst);
2373 56 ($y,$m,$d) = @$date2;
2374  
2375 56 ▶ if ($field_w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field_w) 8 48 56
2376 8 ($y,$m,$d) = @{ $dmb->calc_date_days([$y,$m,$d],7) };
2377 }
2378 }
2379  
2380 } else {
2381 450 return ();
2382 }
2383  
2384 874 return($y,$m,$d,$dow);
2385 }
2386  
2387 # Supply defaults for missing values (Y/M/D)
2388 1917 ▶sub _def_date {
Subroutine _def_date: called CC=9 SCAR=22.0
2389 1917 my($self,$y,$m,$d,$noupdate) = @_;
2390 1917 ▶ $y = '' if (! defined $y);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $y 324 1593 1917
2391 1917 ▶ $m = '' if (! defined $m);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $m 65 1852 1917
2392 1917 ▶ $d = '' if (! defined $d);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $d 69 1848 1917
2393 1917 my $defined = 0;
2394 1917 my $dmt = $$self{'tz'};
2395 1917 my $dmb = $$dmt{'base'};
2396  
2397 # If year was not specified, defaults to current year.
2398 #
2399 # We'll also fix the year (turn 2-digit into 4-digit).
2400  
2401 1917 ▶ if ($y eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($y eq '') { } 324 1593 1917
2402 324 $y = $dmt->_now('y',$$noupdate);
2403 324 $$noupdate = 1;
2404 324 $$self{'data'}{'def'}[0] = '';
2405 } else {
2406 1593 $y = $dmt->_fix_year($y);
2407 1593 $defined = 1;
2408 }
2409  
2410 # If the month was not specifed, but the year was, a default of
2411 # 01 is supplied (this is a truncated date).
2412 #
2413 # If neither was specified, month defaults to the current month.
2414  
2415 1917 ▶ if ($m ne '') {
Branch: 2 branches
BranchTrueFalseTotal
if ($m ne '') { } 1852 65 1917
elsif ($defined) { } 4 61 65
2416 1852 $defined = 1;
2417 } elsif ($defined) {
2418 4 $m = 1;
2419 4 $$self{'data'}{'def'}[1] = 1;
2420 } else {
2421 61 $m = $dmt->_now('m',$$noupdate);
2422 61 $$noupdate = 1;
2423 61 $$self{'data'}{'def'}[1] = '';
2424 }
2425  
2426 # If the day was not specified, but the year or month was, a default
2427 # of 01 is supplied (this is a truncated date).
2428 #
2429 # If none were specified, it default to the current day.
2430  
2431 1917 ▶ if ($d ne '') {
Branch: 2 branches
BranchTrueFalseTotal
if ($d ne '') { } 1848 69 1917
elsif ($defined) { } 13 56 69
2432 1848 $defined = 1;
2433 } elsif ($defined) {
2434 13 $d = 1;
2435 13 $$self{'data'}{'def'}[2] = 1;
2436 } else {
2437 56 $d = $dmt->_now('d',$$noupdate);
2438 56 $$noupdate = 1;
2439 56 $$self{'data'}{'def'}[2] = '';
2440 }
2441  
2442 1917 return($y,$m,$d);
2443 }
2444  
2445 # Supply defaults for missing values (Y/DoY)
2446 23 ▶sub _def_date_doy {
Subroutine _def_date_doy: called CC=3 SCAR=11.0
2447 23 my($self,$y,$doy,$noupdate) = @_;
2448 23 ▶ $y = '' if (! defined $y);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $y 2 21 23
2449 23 my $dmt = $$self{'tz'};
2450 23 my $dmb = $$dmt{'base'};
2451  
2452 # If year was not specified, defaults to current year.
2453 #
2454 # We'll also fix the year (turn 2-digit into 4-digit).
2455  
2456 23 ▶ if ($y eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($y eq '') { } 2 21 23
2457 2 $y = $dmt->_now('y',$$noupdate);
2458 2 $$noupdate = 1;
2459 2 $$self{'data'}{'def'}[0] = '';
2460 } else {
2461 21 $y = $dmt->_fix_year($y);
2462 }
2463  
2464 # DoY must be specified.
2465  
2466 23 my($m,$d);
2467 23 my $ymd = $dmb->day_of_year($y,$doy);
2468  
2469 23 return @$ymd;
2470 }
2471  
2472 # Supply defaults for missing values (YY/Www/D) and (Y/Www/D)
2473 69 ▶sub _def_date_dow {
Subroutine _def_date_dow: called CC=10 SCAR=23.3
2474 69 my($self,$y,$w,$dow,$noupdate) = @_;
2475 69 ▶ $y = '' if (! defined $y);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $y 20 49 69
2476 69 ▶ $w = '' if (! defined $w);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $w 8 61 69
2477 69 ▶ $dow = '' if (! defined $dow);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dow 18 51 69
2478 69 my $dmt = $$self{'tz'};
2479 69 my $dmb = $$dmt{'base'};
2480  
2481 # If year was not specified, defaults to current year.
2482 #
2483 # If it was specified and is a single digit, it is the
2484 # year in the current decade.
2485 #
2486 # We'll also fix the year (turn 2-digit into 4-digit).
2487  
2488 69 ▶ if ($y ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($y ne '') { } 49 20 69
2489 49 ▶ if (length($y) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $y == 1) { } 0 49 49
2490 0 my $tmp = $dmt->_now('y',$$noupdate);
2491 0 $tmp =~ s/.$/$y/;
2492 0 $y = $tmp;
2493 0 $$noupdate = 1;
2494  
2495 } else {
2496 49 $y = $dmt->_fix_year($y);
2497  
2498 }
2499  
2500 } else {
2501 20 $y = $dmt->_now('y',$$noupdate);
2502 20 $$noupdate = 1;
2503 20 $$self{'data'}{'def'}[0] = '';
2504 }
2505  
2506 # If week was not specified, it defaults to the current
2507 # week. Get the first day of the week.
2508  
2509 69 my($m,$d);
2510 69 ▶ if ($w ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($w ne '') { } 61 8 69
2511 61 ($y,$m,$d) = @{ $dmb->week_of_year($y,$w) };
2512 } else {
2513 8 my($nowy,$nowm,$nowd) = $dmt->_now('now',$$noupdate);
2514 8 $$noupdate = 1;
2515 8 my $noww;
2516 8 ($nowy,$noww) = $dmb->week_of_year([$nowy,$nowm,$nowd]);
2517 8 ($y,$m,$d) = @{ $dmb->week_of_year($nowy,$noww) };
2518 }
2519  
2520 # Handle the DoW
2521  
2522 69 ▶ if ($dow eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dow eq "") 18 51 69
2523 18 $dow = 1;
2524 }
2525 69 my $n = $dmb->days_in_month($y,$m);
2526 69 $d += ($dow-1);
2527 69 ▶ if ($d > $n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d > $n) 5 64 69
2528 5 $m++;
2529 5 ▶ if ($m==13) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m == 13) 0 5 5
2530 0 $y++;
2531 0 $m = 1;
2532 }
2533 5 $d = $d-$n;
2534 }
2535  
2536 69 return($y,$m,$d);
2537 }
2538  
2539 # Supply defaults for missing values (HH:MN:SS)
2540 2590 ▶sub _def_time {
Subroutine _def_time: called CC=11 SCAR=24.8
2541 2590 my($self,$h,$m,$s,$noupdate) = @_;
2542 2590 ▶ $h = '' if (! defined $h);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h 126 2464 2590
2543 2590 ▶ $m = '' if (! defined $m);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $m 143 2447 2590
2544 2590 ▶ $s = '' if (! defined $s);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 413 2177 2590
2545 2590 my $defined = 0;
2546 2590 my $dmt = $$self{'tz'};
2547 2590 my $dmb = $$dmt{'base'};
2548  
2549 # If no time was specified, defaults to 00:00:00.
2550  
2551 2590 ▶ if ($h eq '' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($h eq "" and $m eq "" and $s eq "") 126 2464 2590
Condition66%4/6
$h eq "" and $m eq "" and $s eq ""
!ll&&!rl&&r
24640126
$h eq "" and $m eq ""
!ll&&!rl&&r
24640126
MC/DC33%1/3
$h eq "" and $m eq "" and $s eq ""
$h eq "" $m eq "" $s eq ""
Truth table50%2/4
A and B and C
A= $h eq ""B= $m eq ""C= $s eq ""
ABCresult
0XX0
10X0
1100
1111
2552 $m eq '' &&
2553 $s eq '') {
2554 126 $$self{'data'}{'def'}[3] = 1;
2555 126 $$self{'data'}{'def'}[4] = 1;
2556 126 $$self{'data'}{'def'}[5] = 1;
2557 126 return(0,0,0);
2558 }
2559  
2560 # If hour was not specified, defaults to current hour.
2561  
2562 2464 ▶ if ($h ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($h ne '') { } 2464 0 2464
2563 2464 $defined = 1;
2564 } else {
2565 0 $h = $dmt->_now('h',$$noupdate);
2566 0 $$noupdate = 1;
2567 0 $$self{'data'}{'def'}[3] = '';
2568 }
2569  
2570 # If the minute was not specifed, but the hour was, a default of
2571 # 00 is supplied (this is a truncated time).
2572 #
2573 # If neither was specified, minute defaults to the current minute.
2574  
2575 2464 ▶ if ($m ne '') {
Branch: 2 branches
BranchTrueFalseTotal
if ($m ne '') { } 2447 17 2464
elsif ($defined) { } 17 0 17
2576 2447 $defined = 1;
2577 } elsif ($defined) {
2578 17 $m = 0;
2579 17 $$self{'data'}{'def'}[4] = 1;
2580 } else {
2581 0 $m = $dmt->_now('mn',$$noupdate);
2582 0 $$noupdate = 1;
2583 0 $$self{'data'}{'def'}[4] = '';
2584 }
2585  
2586 # If the second was not specified (either the hour or the minute were),
2587 # a default of 00 is supplied (this is a truncated time).
2588  
2589 2464 ▶ if ($s eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq "") 287 2177 2464
2590 287 $s = 0;
2591 287 $$self{'data'}{'def'}[5] = 1;
2592 }
2593  
2594 2464 return($h,$m,$s);
2595 }
2596  
2597 ########################################################################
2598 # OTHER DATE METHODS
2599 ########################################################################
2600  
2601 # Gets the date in the parsed timezone (if $type = ''), local timezone
2602 # (if $type = 'local') or GMT timezone (if $type = 'gmt').
2603 #
2604 # Gets the string value in scalar context, the split value in list
2605 # context.
2606 #
2607 32662 ▶sub value {
Subroutine value: called CC=14 SCAR=26.9
Pod documented
2608 32662 my($self,$type) = @_;
2609 32662 my $dmt = $$self{'tz'};
2610 32662 my $dmb = $$dmt{'base'};
2611 32662 my $date;
2612  
2613 32662 while (1) {
2614 32662 ▶ if (! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"data"}{"set"}) 15 32647 32662
2615 15 $$self{'err'} = '[value] Object does not contain a date';
2616 15 last;
2617 }
2618  
2619 32647 ▶ $type = '' if (! $type);
Branch: 1 branch
BranchTrueFalseTotal
unless $type 29440 3207 32647
2620  
2621 32647 ▶ if ($type eq 'gmt') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'gmt') { } 2988 29659 32647
elsif ($type eq 'local') { } 219 29440 29659
2622  
2623 2988 ▶ if (! @{ $$self{'data'}{'gmt'} }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"data"}{"gmt"};}) 2686 302 2988
2624 2686 my $zone = $$self{'data'}{'tz'};
2625 2686 my $date = $$self{'data'}{'date'};
2626  
2627 2686 ▶ if ($zone eq 'Etc/GMT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone eq 'Etc/GMT') { } 0 2686 2686
2628 0 $$self{'data'}{'gmt'} = $date;
2629  
2630 } else {
2631 2686 my $isdst = $$self{'data'}{'isdst'};
2632 2686 my($err,$d) = $dmt->convert_to_gmt($date,$zone,$isdst);
2633 2686 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 2686 2686
2634 0 $$self{'err'} = '[value] Unable to convert date to GMT';
2635 0 last;
2636 }
2637 2686 $$self{'data'}{'gmt'} = $d;
2638 }
2639 }
2640 2988 $date = $$self{'data'}{'gmt'};
2641  
2642 } elsif ($type eq 'local') {
2643  
2644 219 ▶ if (! @{ $$self{'data'}{'loc'} }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"data"}{"loc"};}) 219 0 219
2645 219 my $zone = $$self{'data'}{'tz'};
2646 219 $date = $$self{'data'}{'date'};
2647 219 my $local = $dmt->_now('tz',1);
2648  
2649 219 ▶ if ($zone eq $local) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone eq $local) { } 192 27 219
2650 192 $$self{'data'}{'loc'} = $date;
2651  
2652 } else {
2653 27 my $isdst = $$self{'data'}{'isdst'};
2654 27 my($err,$d) = $dmt->convert_to_local($date,$zone,$isdst);
2655 27 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 27 27
2656 0 $$self{'err'} = '[value] Unable to convert date to localtime';
2657 0 last;
2658 }
2659 27 $$self{'data'}{'loc'} = $d;
2660 }
2661 }
2662 219 $date = $$self{'data'}{'loc'};
2663  
2664 } else {
2665  
2666 29440 $date = $$self{'data'}{'date'};
2667  
2668 }
2669  
2670 32647 last;
2671 }
2672  
2673 32662 ▶ if ($$self{'err'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"}) 18 32644 32662
2674 18 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 18 0 18
2675 18 return ();
2676 } else {
2677 0 return '';
2678 }
2679 }
2680  
2681 32644 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 7934 24710 32644
2682 7934 return @$date;
2683 } else {
2684 24710 return $dmb->join('date',$date);
2685 }
2686 }
2687  
2688 10657 ▶sub cmp {
Subroutine cmp: called CC=7 SCAR=23.6
Pod documented
2689 10657 my($self,$date) = @_;
2690 10657 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 10657 10657
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
0010657
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
2691 0 carp "WARNING: [cmp] Arguments must be valid dates: date1";
2692 0 return undef;
2693 }
2694  
2695 10657 ▶ if (! (ref($date) eq 'Date::Manip::Date')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $date eq "Date::Manip::Date") 0 10657 10657
2696 0 carp "WARNING: [cmp] Argument must be a Date::Manip::Date object";
2697 0 return undef;
2698 }
2699 10657 ▶ if ($$date{'err'} || ! $$date{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date->{"err"} or not $date->{"data"}{"set"}) 0 10657 10657
Condition33%1/3
$date->{"err"} or not $date->{"data"}{"set"}
l!l&&r!l&&!r
0010657
MC/DC0%0/2
$date->{"err"} or not $date->{"data"}{"set"}
$date->{"err"} not $date->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $date->{"err"}B= not $date->{"data"}{"set"}
ABresult
1X1
011
000
2700 0 carp "WARNING: [cmp] Arguments must be valid dates: date2";
2701 0 return undef;
2702 }
2703  
2704 10657 my($d1,$d2);
2705 10657 ▶ if ($$self{'data'}{'tz'} eq $$date{'data'}{'tz'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'data'}{'tz'} eq $date->{'data'}{'tz'}) { } 10656 1 10657
2706 10656 $d1 = $self->value();
2707 10656 $d2 = $date->value();
2708 } else {
2709 1 $d1 = $self->value('gmt');
2710 1 $d2 = $date->value('gmt');
2711 }
2712  
2713 10657 return ($d1 cmp $d2);
2714 }
2715  
2716 170 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
2717 170 my %field = qw(y 0 m 1 d 2 h 3 mn 4 s 5);
2718  
2719 10524 ▶ sub set {
Subroutine set: called CC=55 SCAR=51.5
Pod documented
2720 10524 my($self,$field,@val) = @_;
2721 10524 $field = lc($field);
2722 10524 my $dmt = $$self{'tz'};
2723 10524 my $dmb = $$dmt{'base'};
2724  
2725 # Make sure $self includes a valid date (unless the entire date is
2726 # being set, in which case it doesn't matter).
2727  
2728 10524 my $date = [];
2729 10524 my(@def,$tz,$isdst);
2730  
2731 10524 ▶ if ($field eq 'zdate') {
Branch: 2 branches
BranchTrueFalseTotal
if ($field eq 'zdate') { } 4889 5635 10524
elsif ($field eq 'date') { } 5569 66 5635
2732 # If {data}{set} = 2, we want to preserve the defaults. Also, we've
2733 # already initialized.
2734 #
2735 # It is only set in the parse routines which means that this was
2736 # called via _parse_check.
2737  
2738 4889 ▶ $self->_init() if ($$self{'data'}{'set'} != 2);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"data"}{"set"} != 2 4 4885 4889
2739 4889 @def = @{ $$self{'data'}{'def'} };
2740  
2741 } elsif ($field eq 'date') {
2742 5569 ▶ if ($$self{'data'}{'set'} && ! $$self{'err'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'data'}{'set'} and not $self->{'err'}) { } 319 5250 5569
Condition66%2/3
$self->{"data"}{"set"} and not $self->{"err"}
!ll&&!rl&&r
52500319
MC/DC50%1/2
$self->{"data"}{"set"} and not $self->{"err"}
$self->{"data"}{"set"} not $self->{"err"}
Truth table66%2/3
A and not(B)
A= $self->{"data"}{"set"}B= not $self->{"err"}
ABresult
0X0
100
111
2743 319 $tz = $$self{'data'}{'tz'};
2744 } else {
2745 5250 $tz = $dmt->_now('tz',1);
2746 }
2747 5569 $self->_init();
2748 5569 @def = @{ $$self{'data'}{'def'} };
2749  
2750 } else {
2751 66 ▶ return 1 if ($$self{'err'} || ! $$self{'data'}{'set'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} or not $self->{"data"}{"set"} 0 66 66
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
0066
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
2752 66 $date = $$self{'data'}{'date'};
2753 66 $tz = $$self{'data'}{'tz'};
2754 66 $isdst = $$self{'data'}{'isdst'};
2755 66 @def = @{ $$self{'data'}{'def'} };
2756 66 $self->_init();
2757 }
2758  
2759 # Check the arguments
2760  
2761 10524 my($err,$new_tz,$new_date,$new_time);
2762  
2763 10524 ▶ if ($field eq 'date') {
Branch: 5 branches
BranchTrueFalseTotal
if ($field eq 'date') { } 5569 4955 10524
elsif ($field eq 'time') { } 64 4891 4955
elsif ($field eq 'zdate') { } 4889 2 4891
elsif ($field eq 'zone') { } 0 2 2
elsif (exists $field{$field}) { } 2 0 2
2764  
2765 5569 ▶ if ($#val == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($#val == 0) { } 5554 15 5569
elsif ($#val == 1) { } 15 0 15
2766 # date,DATE
2767 5554 $new_date = $val[0];
2768 } elsif ($#val == 1) {
2769 # date,DATE,ISDST
2770 15 ($new_date,$isdst) = @val;
2771 } else {
2772 0 $err = 1;
2773 }
2774 5569 ▶ for (my $i=0; $i<=5; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= 5) 33414 5569 38983
2775 33414 ▶ $def[$i] = 0 if ($def[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $def[$i] 0 33414 33414
2776 }
2777  
2778 } elsif ($field eq 'time') {
2779  
2780 64 ▶ if ($#val == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($#val == 0) { } 64 0 64
elsif ($#val == 1) { } 0 0 0
2781 # time,TIME
2782 64 $new_time = $val[0];
2783 } elsif ($#val == 1) {
2784 # time,TIME,ISDST
2785 0 ($new_time,$isdst) = @val;
2786 } else {
2787 0 $err = 1;
2788 }
2789 64 ▶ $def[3] = 0 if ($def[3]);
Branch: 1 branch
BranchTrueFalseTotal
if $def[3] 0 64 64
2790 64 ▶ $def[4] = 0 if ($def[4]);
Branch: 1 branch
BranchTrueFalseTotal
if $def[4] 0 64 64
2791 64 ▶ $def[5] = 0 if ($def[5]);
Branch: 1 branch
BranchTrueFalseTotal
if $def[5] 1 63 64
2792  
2793 } elsif ($field eq 'zdate') {
2794  
2795 4889 ▶ if ($#val == 0) {
Branch: 4 branches
BranchTrueFalseTotal
if ($#val == 0) { } 2 4887 4889
elsif ($#val == 1 and $val[1] eq '0' || $val[1] eq '1') { } 0 4887 4887
elsif ($#val == 1) { } 2 4885 4887
elsif ($#val == 2) { } 4885 0 4885
2796 # zdate,DATE
2797 2 $new_date = $val[0];
2798 ▶ } elsif ($#val == 1 && ($val[1] eq '0' || $val[1] eq '1')) {
Condition50%3/6
$#val == 1 and $val[1] eq 0 || $val[1] eq 1
!ll&&!rl&&r
488520
$val[1] eq 0 or $val[1] eq 1
l!l&&r!l&&!r
002
MC/DC0%0/3
$#val == 1 and $val[1] eq 0 || $val[1] eq 1
$#val == 1 $val[1] eq 0 $val[1] eq 1
Truth table50%2/4
A and B or C
A= $#val == 1B= $val[1] eq 0C= $val[1] eq 1
ABCresult
0XX0
1000
11X1
1011
2799 # zdate,DATE,ISDST
2800 0 ($new_date,$isdst) = @val;
2801 } elsif ($#val == 1) {
2802 # zdate,ZONE,DATE
2803 2 ($new_tz,$new_date) = @val;
2804 } elsif ($#val == 2) {
2805 # zdate,ZONE,DATE,ISDST
2806 4885 ($new_tz,$new_date,$isdst) = @val;
2807 } else {
2808 0 $err = 1;
2809 }
2810 4889 ▶ if ($$self{'data'}{'set'} != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data"}{"set"} != 2) 4 4885 4889
2811 4 ▶ for (my $i=0; $i<=5; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= 5) 24 4 28
2812 24 ▶ $def[$i] = 0 if ($def[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $def[$i] 0 24 24
2813 }
2814 }
2815 4889 ▶ $tz = $dmt->_now('tz',1) if (! $new_tz);
Branch: 1 branch
BranchTrueFalseTotal
unless $new_tz 2 4887 4889
2816  
2817 } elsif ($field eq 'zone') {
2818  
2819 0 ▶ if ($#val == -1) {
Branch: 4 branches
BranchTrueFalseTotal
if ($#val == -1) { } 0 0 0
elsif ($#val == 0 and $val[0] eq '0' || $val[0] eq '1') { } 0 0 0
elsif ($#val == 0) { } 0 0 0
elsif ($#val == 1) { } 0 0 0
2820 # zone
2821 ▶ } elsif ($#val == 0 && ($val[0] eq '0' || $val[0] eq '1')) {
Condition0%0/6
$#val == 0 and $val[0] eq 0 || $val[0] eq 1
!ll&&!rl&&r
000
$val[0] eq 0 or $val[0] eq 1
l!l&&r!l&&!r
000
MC/DC0%0/3
$#val == 0 and $val[0] eq 0 || $val[0] eq 1
$#val == 0 $val[0] eq 0 $val[0] eq 1
Truth table0%0/4
A and B or C
A= $#val == 0B= $val[0] eq 0C= $val[0] eq 1
ABCresult
0XX0
1000
11X1
1011
2822 # zone,ISDST
2823 0 $isdst = $val[0];
2824 } elsif ($#val == 0) {
2825 # zone,ZONE
2826 0 $new_tz = $val[0];
2827 } elsif ($#val == 1) {
2828 # zone,ZONE,ISDST
2829 0 ($new_tz,$isdst) = @val;
2830 } else {
2831 0 $err = 1;
2832 }
2833 0 ▶ $tz = $dmt->_now('tz',1) if (! $new_tz);
Branch: 1 branch
BranchTrueFalseTotal
unless $new_tz 0 0 0
2834  
2835 } elsif (exists $field{$field}) {
2836  
2837 2 my $i = $field{$field};
2838 2 my $val;
2839 2 ▶ if ($#val == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($#val == 0) { } 2 0 2
elsif ($#val == 1) { } 0 0 0
2840 2 $val = $val[0];
2841 } elsif ($#val == 1) {
2842 0 ($val,$isdst) = @val;
2843 } else {
2844 0 $err = 1;
2845 }
2846  
2847 2 $$date[$i] = $val;
2848 2 ▶ $def[$i] = 0 if ($def[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $def[$i] 0 2 2
2849  
2850 } else {
2851  
2852 0 $err = 2;
2853  
2854 }
2855  
2856 10524 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 10524 10524
2857 0 ▶ if ($err == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err == 1) { } 0 0 0
2858 0 $$self{'err'} = '[set] Invalid arguments';
2859 } else {
2860 0 $$self{'err'} = '[set] Invalid field';
2861 }
2862 0 return 1;
2863 }
2864  
2865 # Handle the arguments (it can be a zone or an offset)
2866  
2867 10524 ▶ if ($new_tz) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_tz) 4887 5637 10524
2868 4887 my $tmp = $dmt->_zone($new_tz);
2869 4887 ▶ if ($tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp) { } 4887 0 4887
2870 # A zone/alias
2871 4887 $tz = $tmp;
2872  
2873 } else {
2874 # An offset
2875  
2876 0 my $dstflag = '';
2877 0 ▶ $dstflag = ($isdst ? 'dstonly' : 'stdonly') if (defined $isdst);
Branch: 2 branches
BranchTrueFalseTotal
if defined $isdst 0 0 0
$isdst ? : 0 0 0
2878  
2879 0 $tz = $dmb->__zone($date,lc($new_tz),'',$dstflag);
2880  
2881 0 ▶ if (! $tz) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tz) 0 0 0
2882 0 $$self{'err'} = "[set] Invalid timezone argument: $new_tz";
2883 0 return 1;
2884 }
2885 }
2886 }
2887  
2888 10524 ▶ if ($new_date) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_date) 10458 66 10524
2889 10458 ▶ if ($dmb->check($new_date)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dmb->check($new_date)) { } 10454 4 10458
2890 10454 $date = $new_date;
2891 } else {
2892 4 $$self{'err'} = '[set] Invalid date argument';
2893 4 return 1;
2894 }
2895 }
2896  
2897 10520 ▶ if ($new_time) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_time) 64 10456 10520
2898 64 ▶ if ($dmb->check_time($new_time)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dmb->check_time($new_time)) { } 64 0 64
2899 64 $$date[3] = $$new_time[0];
2900 64 $$date[4] = $$new_time[1];
2901 64 $$date[5] = $$new_time[2];
2902 } else {
2903 0 $$self{'err'} = '[set] Invalid time argument';
2904 0 return 1;
2905 }
2906 }
2907  
2908 # Check the date/timezone combination
2909  
2910 10520 my($abb,$off);
2911 10520 ▶ if ($tz eq 'etc/gmt') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tz eq 'etc/gmt') { } 42 10478 10520
2912 42 $abb = 'GMT';
2913 42 $off = [0,0,0];
2914 42 $isdst = 0;
2915 } else {
2916 10478 my $per = $dmt->date_period($date,$tz,1,$isdst);
2917 10478 ▶ if (! $per) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($per) 3 10475 10478
2918 3 $$self{'err'} = '[set] Invalid date/timezone';
2919 3 return 1;
2920 }
2921 10475 $isdst = $$per[5];
2922 10475 $abb = $$per[4];
2923 10475 $off = $$per[3];
2924 }
2925  
2926 # Set the information
2927  
2928 10517 $$self{'data'}{'set'} = 1;
2929 10517 $$self{'data'}{'date'} = $date;
2930 10517 $$self{'data'}{'tz'} = $tz;
2931 10517 $$self{'data'}{'isdst'} = $isdst;
2932 10517 $$self{'data'}{'offset'}= $off;
2933 10517 $$self{'data'}{'abb'} = $abb;
2934 10517 $$self{'data'}{'def'} = [ @def ];
2935  
2936 10517 return 0;
2937 }
2938 }
2939  
2940 ########################################################################
2941 # NEXT/PREV METHODS
2942  
2943 75 ▶sub prev {
Subroutine prev: called CC=4 SCAR=14.8
Pod documented
2944 75 my($self,@args) = @_;
2945 75 ▶ return 1 if ($$self{'err'} || ! $$self{'data'}{'set'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} or not $self->{"data"}{"set"} 0 75 75
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
0075
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
2946 75 my $date = $$self{'data'}{'date'};
2947  
2948 75 $date = $self->__next_prev($date,0,@args);
2949  
2950 75 ▶ return 1 if (! defined($date));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 0 75 75
2951 75 $self->set('date',$date);
2952 75 return 0;
2953 }
2954  
2955 75 ▶sub next {
Subroutine next: called CC=4 SCAR=14.8
Pod documented
2956 75 my($self,@args) = @_;
2957 75 ▶ return 1 if ($$self{'err'} || ! $$self{'data'}{'set'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"err"} or not $self->{"data"}{"set"} 0 75 75
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
0075
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
2958 75 my $date = $$self{'data'}{'date'};
2959  
2960 75 $date = $self->__next_prev($date,1,@args);
2961  
2962 75 ▶ return 1 if (! defined($date));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 0 75 75
2963 75 $self->set('date',$date);
2964 75 return 0;
2965 }
2966  
2967 1198 ▶sub __next_prev {
Subroutine __next_prev: called CC=41 SCAR=39.1
2968 1198 my($self,$date,$next,$dow,$curr,$time) = @_;
2969  
2970 1198 my ($caller,$sign,$prev);
2971 1198 ▶ if ($next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next) { } 944 254 1198
2972 944 $caller = 'next';
2973 944 $sign = 1;
2974 944 $prev = 0;
2975 } else {
2976 254 $caller = 'prev';
2977 254 $sign = -1;
2978 254 $prev = 1;
2979 }
2980  
2981 1198 my $dmt = $$self{'tz'};
2982 1198 my $dmb = $$dmt{'base'};
2983 1198 my $orig = [ @$date ];
2984  
2985 # Check the time (if any)
2986  
2987 1198 ▶ if (defined($time)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $time) 366 832 1198
2988 366 ▶ if ($dow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dow) { } 34 332 366
2989 # $time will refer to a full [H,MN,S]
2990 34 my($err,$h,$mn,$s) = $dmb->_hms_fields({ 'out' => 'list' },$time);
2991 34 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 34 34
2992 0 $$self{'err'} = "[$caller] invalid time argument";
2993 0 return undef;
2994 }
2995 34 $time = [$h,$mn,$s];
2996 } else {
2997 # $time may have leading undefs
2998 332 my @tmp = @$time;
2999 332 ▶ if ($#tmp != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#tmp != 2) 0 332 332
3000 0 $$self{'err'} = "[$caller] invalid time argument";
3001 0 return undef;
3002 }
3003 332 my($h,$mn,$s) = @$time;
3004 332 ▶ if (defined($h)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $h) { } 296 36 332
elsif (defined $mn) { } 24 12 36
3005 296 ▶ $mn = 0 if (! defined($mn));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mn 14 282 296
3006 296 ▶ $s = 0 if (! defined($s));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 3 293 296
3007 } elsif (defined($mn)) {
3008 24 ▶ $s = 0 if (! defined($s));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 24 24
3009 } else {
3010 12 ▶ $s = 0 if (! defined($s));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 12 12
3011 }
3012 332 $time = [$h,$mn,$s];
3013 }
3014 }
3015  
3016 # Find the next DoW
3017  
3018 1198 ▶ if ($dow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dow) 866 332 1198
3019  
3020 866 ▶ if (! $dmb->_is_int($dow,1,7)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dmb->_is_int($dow, 1, 7)) 0 866 866
3021 0 $$self{'err'} = "[$caller] Invalid DOW: $dow";
3022 0 return undef;
3023 }
3024  
3025 # Find the next/previous occurrence of DoW
3026  
3027 866 my $curr_dow = $dmb->day_of_week($date);
3028 866 my $adjust = 0;
3029  
3030 866 ▶ if ($dow == $curr_dow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dow == $curr_dow) { } 182 684 866
3031 182 ▶ $adjust = 1 if ($curr == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $curr == 0 62 120 182
3032  
3033 } else {
3034 684 my $num;
3035 684 ▶ if ($next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next) { } 559 125 684
3036 # force $dow to be more than $curr_dow
3037 559 ▶ $dow += 7 if ($dow<$curr_dow);
Branch: 1 branch
BranchTrueFalseTotal
if $dow < $curr_dow 454 105 559
3038 559 $num = $dow - $curr_dow;
3039 } else {
3040 # force $dow to be less than $curr_dow
3041 125 ▶ $dow -= 7 if ($dow>$curr_dow);
Branch: 1 branch
BranchTrueFalseTotal
if $dow > $curr_dow 20 105 125
3042 125 $num = $curr_dow - $dow;
3043 125 $num *= -1;
3044 }
3045  
3046 # Add/subtract $num days
3047 684 $date = $dmb->calc_date_days($date,$num);
3048 }
3049  
3050 866 ▶ if (defined($time)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $time) 34 832 866
3051 34 my ($y,$m,$d,$h,$mn,$s) = @$date;
3052 34 ($h,$mn,$s) = @$time;
3053 34 $date = [$y,$m,$d,$h,$mn,$s];
3054 }
3055  
3056 866 my $cmp = $dmb->cmp($orig,$date);
3057 866 ▶ $adjust = 1 if ($curr == 2 && $cmp != -1*$sign);
Branch: 1 branch
BranchTrueFalseTotal
if $curr == 2 and $cmp != -1 * $sign 8 858 866
Condition100%3/3
$curr == 2 and $cmp != -1 * $sign
!ll&&!rl&&r
85628
MC/DC100%2/2
$curr == 2 and $cmp != -1 * $sign
$curr == 2 $cmp != -1 * $sign
Truth table100%3/3
A and B
A= $curr == 2B= $cmp != -1 * $sign
ABresult
0X0
100
111
3058  
3059 866 ▶ if ($adjust) {
Branch: 1 branch
BranchTrueFalseTotal
if ($adjust) 70 796 866
3060 # Add/subtract 1 week
3061 70 $date = $dmb->calc_date_days($date,$sign*7);
3062 }
3063  
3064 866 return $date;
3065 }
3066  
3067 # Find the next Time
3068  
3069 332 ▶ if (defined($time)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $time) 332 0 332
3070  
3071 332 my ($h,$mn,$s) = @$time;
3072 332 my $orig = [ @$date ];
3073  
3074 332 my $cmp;
3075 332 ▶ if (defined $h) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $h) { } 296 36 332
elsif (defined $mn) { } 24 12 36
3076 # Find next/prev HH:MN:SS
3077  
3078 296 @$date[3..5] = @$time;
3079 296 $cmp = $dmb->cmp($orig,$date);
3080 296 ▶ if ($cmp == -1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmp == -1) { } 109 187 296
elsif ($cmp == 1) { } 69 118 187
3081 109 ▶ if ($prev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev) 10 99 109
3082 10 $date = $dmb->calc_date_days($date,-1);
3083 }
3084 } elsif ($cmp == 1) {
3085 69 ▶ if ($next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next) 69 0 69
3086 69 $date = $dmb->calc_date_days($date,1);
3087 }
3088 } else {
3089 118 ▶ if (! $curr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($curr) 102 16 118
3090 102 $date = $dmb->calc_date_days($date,$sign);
3091 }
3092 }
3093  
3094 } elsif (defined $mn) {
3095 # Find next/prev MN:SS
3096  
3097 24 @$date[4..5] = @$time[1..2];
3098  
3099 24 $cmp = $dmb->cmp($orig,$date);
3100 24 ▶ if ($cmp == -1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmp == -1) { } 0 24 24
elsif ($cmp == 1) { } 8 16 24
3101 0 ▶ if ($prev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev) 0 0 0
3102 0 $date = $dmb->calc_date_time($date,[-1,0,0]);
3103 }
3104 } elsif ($cmp == 1) {
3105 8 ▶ if ($next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next) 4 4 8
3106 4 $date = $dmb->calc_date_time($date,[1,0,0]);
3107 }
3108 } else {
3109 16 ▶ if (! $curr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($curr) 8 8 16
3110 8 $date = $dmb->calc_date_time($date,[$sign,0,0]);
3111 }
3112 }
3113  
3114 } else {
3115 # Find next/prev SS
3116  
3117 12 $$date[5] = $$time[2];
3118  
3119 12 $cmp = $dmb->cmp($orig,$date);
3120 12 ▶ if ($cmp == -1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmp == -1) { } 0 12 12
elsif ($cmp == 1) { } 0 12 12
3121 0 ▶ if ($prev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev) 0 0 0
3122 0 $date = $dmb->calc_date_time($date,[0,-1,0]);
3123 }
3124 } elsif ($cmp == 1) {
3125 0 ▶ if ($next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next) 0 0 0
3126 0 $date = $dmb->calc_date_time($date,[0,1,0]);
3127 }
3128 } else {
3129 12 ▶ if (! $curr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($curr) 8 4 12
3130 8 $date = $dmb->calc_date_time($date,[0,$sign,0]);
3131 }
3132 }
3133 }
3134  
3135 332 return $date;
3136 }
3137  
3138 0 $$self{'err'} = "[$caller] Either DoW or time (or both) required";
3139 0 return undef;
3140 }
3141  
3142 ########################################################################
3143 # CALC METHOD
3144  
3145 4608 ▶sub calc {
Subroutine calc: called CC=3 SCAR=11.3
Pod documented
3146 4608 my($self,$obj,@args) = @_;
3147  
3148 4608 ▶ if (ref($obj) eq 'Date::Manip::Date') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $obj eq 'Date::Manip::Date') { } 1430 3178 4608
elsif (ref $obj eq 'Date::Manip::Delta') { } 3178 0 3178
3149 1430 return $self->_calc_date_date($obj,@args);
3150  
3151 } elsif (ref($obj) eq 'Date::Manip::Delta') {
3152 3178 return $self->_calc_date_delta($obj,@args);
3153  
3154 } else {
3155 0 return undef;
3156 }
3157 }
3158  
3159 1430 ▶sub _calc_date_date {
Subroutine _calc_date_date: called CC=26 SCAR=34.3
3160 1430 my($self,$date,@args) = @_;
3161 1430 my $ret = $self->new_delta();
3162  
3163 1430 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 1430 1430
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
001430
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
3164 0 $$ret{'err'} = '[calc] First object invalid (date)';
3165 0 return $ret;
3166 }
3167  
3168 1430 ▶ if ($$date{'err'} || ! $$date{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date->{"err"} or not $date->{"data"}{"set"}) 0 1430 1430
Condition33%1/3
$date->{"err"} or not $date->{"data"}{"set"}
l!l&&r!l&&!r
001430
MC/DC0%0/2
$date->{"err"} or not $date->{"data"}{"set"}
$date->{"err"} not $date->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $date->{"err"}B= not $date->{"data"}{"set"}
ABresult
1X1
011
000
3169 0 $$ret{'err'} = '[calc] Second object invalid (date)';
3170 0 return $ret;
3171 }
3172  
3173 # Handle subtract/mode arguments
3174  
3175 1430 my($subtract,$mode);
3176  
3177 1430 ▶ if ($#args == -1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($#args == -1) { } 1155 275 1430
elsif ($#args == 0) { } 226 49 275
elsif ($#args == 1) { } 49 0 49
3178 1155 ($subtract,$mode) = (0,'');
3179 } elsif ($#args == 0) {
3180 226 ▶ if ($args[0] eq '0' || $args[0] eq '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0] eq '0' or $args[0] eq '1') { } 0 226 226
Condition33%1/3
$args[0] eq 0 or $args[0] eq 1
l!l&&r!l&&!r
00226
MC/DC0%0/2
$args[0] eq 0 or $args[0] eq 1
$args[0] eq 0 $args[0] eq 1
Truth table33%1/3
A or B
A= $args[0] eq 0B= $args[0] eq 1
ABresult
1X1
011
000
3181 0 ($subtract,$mode) = ($args[0],'');
3182 } else {
3183 226 ($subtract,$mode) = (0,$args[0]);
3184 }
3185  
3186 } elsif ($#args == 1) {
3187 49 ($subtract,$mode) = @args;
3188 } else {
3189 0 $$ret{'err'} = '[calc] Invalid arguments';
3190 0 return $ret;
3191 }
3192 1430 ▶ $mode = 'exact' if (! $mode);
Branch: 1 branch
BranchTrueFalseTotal
unless $mode 1155 275 1430
3193  
3194 1430 ▶ if ($mode !~ /^(business|bsemi|bapprox|approx|semi|exact)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mode =~ /^(business|bsemi|bapprox|approx|semi|exact)$/i) 0 1430 1430
3195 0 $$ret{'err'} = '[calc] Invalid mode argument';
3196 0 return $ret;
3197 }
3198  
3199 # if business mode
3200 # dates must be in the same timezone
3201 # use dates in that zone
3202 #
3203 # otherwise if both dates are in the same timezone && approx/semi mode
3204 # use the dates in that zone
3205 #
3206 # otherwise
3207 # convert to gmt
3208 # use those dates
3209  
3210 1430 my($date1,$date2,$tz1,$isdst1,$tz2,$isdst2);
3211 1430 ▶ if ($mode eq 'business' || $mode eq 'bapprox' || $mode eq 'bsemi') {
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'business' or $mode eq 'bapprox' or $mode eq 'bsemi') { } 156 1274 1430
elsif ($mode eq 'approx' || $mode eq 'semi' and $self->{'data'}{'tz'} eq $date->{'data'}{'tz'}) { } 86 1188 1274
Condition100%6/6
$mode eq "business" or $mode eq "bapprox" or $mode eq "bsemi"
l!l&&r!l&&!r
106501274
$mode eq "business" or $mode eq "bapprox"
l!l&&r!l&&!r
62441324
MC/DC100%3/3
$mode eq "business" or $mode eq "bapprox" or $mode eq "bsemi"
$mode eq "business" $mode eq "bapprox" $mode eq "bsemi"
Truth table100%4/4
A or B or C
A= $mode eq "business"B= $mode eq "bapprox"C= $mode eq "bsemi"
ABCresult
1XX1
01X1
0011
0000
3212 156 ▶ if ($$self{'data'}{'tz'} eq $$date{'data'}{'tz'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'data'}{'tz'} eq $date->{'data'}{'tz'}) { } 156 0 156
3213 156 $date1 = [ $self->value() ];
3214 156 $date2 = [ $date->value() ];
3215 156 $tz1 = $$self{'data'}{'tz'};
3216 156 $tz2 = $tz1;
3217 156 $isdst1 = $$self{'data'}{'isdst'};
3218 156 $isdst2 = $$date{'data'}{'isdst'};
3219 } else {
3220 0 $$ret{'err'} = '[calc] Dates must be in the same timezone for ' .
3221 'business mode calculations';
3222 0 return $ret;
3223 }
3224  
3225 ▶ } elsif (($mode eq 'approx' || $mode eq 'semi') &&
Condition100%6/6
$mode eq "approx" || $mode eq "semi" and $self->{"data"}{"tz"} eq $date->{"data"}{"tz"}
!ll&&!rl&&r
1186286
$mode eq "approx" or $mode eq "semi"
l!l&&r!l&&!r
68201186
MC/DC100%3/3
$mode eq "approx" || $mode eq "semi" and $self->{"data"}{"tz"} eq $date->{"data"}{"tz"}
$mode eq "approx" $mode eq "semi" $self->{"data"}{"tz"} eq $date->{"data"}{"tz"}
Truth table100%5/5
A or B and C
A= $mode eq "approx"B= $mode eq "semi"C= $self->{"data"}{"tz"} eq $date->{"data"}{"tz"}
ABCresult
00X0
1X00
0100
1X11
0111
3226 $$self{'data'}{'tz'} eq $$date{'data'}{'tz'}) {
3227 86 $date1 = [ $self->value() ];
3228 86 $date2 = [ $date->value() ];
3229 86 $tz1 = $$self{'data'}{'tz'};
3230 86 $tz2 = $tz1;
3231 86 $isdst1 = $$self{'data'}{'isdst'};
3232 86 $isdst2 = $$date{'data'}{'isdst'};
3233  
3234 } else {
3235 1188 $date1 = [ $self->value('gmt') ];
3236 1188 $date2 = [ $date->value('gmt') ];
3237 1188 $tz1 = 'GMT';
3238 1188 $tz2 = $tz1;
3239 1188 $isdst1 = 0;
3240 1188 $isdst2 = 0;
3241 }
3242  
3243 # Do the calculation
3244  
3245 1430 my(@delta);
3246 1430 ▶ if ($subtract) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subtract) { } 42 1388 1430
3247 42 ▶ if ($mode eq 'business' || $mode eq 'exact' || $subtract == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'business' or $mode eq 'exact' or $subtract == 2) { } 23 19 42
Condition100%6/6
$mode eq "business" or $mode eq "exact" or $subtract == 2
l!l&&r!l&&!r
131019
$mode eq "business" or $mode eq "exact"
l!l&&r!l&&!r
8529
MC/DC100%3/3
$mode eq "business" or $mode eq "exact" or $subtract == 2
$mode eq "business" $mode eq "exact" $subtract == 2
Truth table100%4/4
A or B or C
A= $mode eq "business"B= $mode eq "exact"C= $subtract == 2
ABCresult
1XX1
01X1
0011
0000
3248 23 @delta = @{ $self->__calc_date_date($mode,$date2,$tz2,$isdst2,
3249 $date1,$tz1,$isdst1) };
3250 } else {
3251 19 @delta = @{ $self->__calc_date_date($mode,$date1,$tz1,$isdst1,
3252 $date2,$tz2,$isdst2) };
3253 19 @delta = map { -1*$_ } @delta;
3254 }
3255 } else {
3256 1388 @delta = @{ $self->__calc_date_date($mode,$date1,$tz1,$isdst1,
3257 $date2,$tz2,$isdst2) };
3258 }
3259  
3260 # Save the delta
3261  
3262 1430 ▶ if ($mode eq 'business' || $mode eq 'bapprox' || $mode eq 'bsemi') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq 'business' or $mode eq 'bapprox' or $mode eq 'bsemi') { } 156 1274 1430
Condition100%6/6
$mode eq "business" or $mode eq "bapprox" or $mode eq "bsemi"
l!l&&r!l&&!r
106501274
$mode eq "business" or $mode eq "bapprox"
l!l&&r!l&&!r
62441324
MC/DC100%3/3
$mode eq "business" or $mode eq "bapprox" or $mode eq "bsemi"
$mode eq "business" $mode eq "bapprox" $mode eq "bsemi"
Truth table100%4/4
A or B or C
A= $mode eq "business"B= $mode eq "bapprox"C= $mode eq "bsemi"
ABCresult
1XX1
01X1
0011
0000
3263 156 $ret->set('business',\@delta);
3264 } else {
3265 1274 $ret->set('delta',\@delta);
3266 }
3267 1430 return $ret;
3268 }
3269  
3270 1430 ▶sub __calc_date_date {
Subroutine __calc_date_date: called CC=35 SCAR=35.6
3271 1430 my($self,$mode,$date1,$tz1,$isdst1,$date2,$tz2,$isdst2) = @_;
3272 1430 my $dmt = $$self{'tz'};
3273 1430 my $dmb = $$dmt{'base'};
3274  
3275 1430 my($dy,$dm,$dw,$dd,$dh,$dmn,$ds) = (0,0,0,0,0,0,0);
3276  
3277 1430 ▶ if ($mode eq 'approx' || $mode eq 'bapprox') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "approx" or $mode eq "bapprox") 112 1318 1430
Condition100%3/3
$mode eq "approx" or $mode eq "bapprox"
l!l&&r!l&&!r
68441318
MC/DC100%2/2
$mode eq "approx" or $mode eq "bapprox"
$mode eq "approx" $mode eq "bapprox"
Truth table100%3/3
A or B
A= $mode eq "approx"B= $mode eq "bapprox"
ABresult
1X1
011
000
3278 112 my($y1,$m1,$d1,$h1,$mn1,$s1) = @$date1;
3279 112 my($y2,$m2,$d2,$h2,$mn2,$s2) = @$date2;
3280 112 $dy = $y2-$y1;
3281 112 $dm = $m2-$m1;
3282  
3283 112 ▶ if ($dy || $dm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dy or $dm) 90 22 112
Condition100%3/3
$dy or $dm
l!l&&r!l&&!r
672322
MC/DC100%2/2
$dy or $dm
$dy $dm
Truth table100%3/3
A or B
A= $dyB= $dm
ABresult
1X1
011
000
3284 # If $d1 is greater than the number of days allowed in the
3285 # month $y2/$m2, set it equal to the number of days. In other
3286 # words:
3287 # Jan 31 2006 to Feb 28 2008 = 2 years 1 month
3288 #
3289 90 my $dim = $dmb->days_in_month($y2,$m2);
3290 90 ▶ $d1 = $dim if ($d1 > $dim);
Branch: 1 branch
BranchTrueFalseTotal
if $d1 > $dim 6 84 90
3291  
3292 90 $date1 = [$y2,$m2,$d1,$h1,$mn1,$s1];
3293 }
3294 }
3295  
3296 1430 ▶ if ($mode eq 'semi' || $mode eq 'approx') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "semi" or $mode eq "approx") 88 1342 1430
Condition100%3/3
$mode eq "semi" or $mode eq "approx"
l!l&&r!l&&!r
20681342
MC/DC100%2/2
$mode eq "semi" or $mode eq "approx"
$mode eq "semi" $mode eq "approx"
Truth table100%3/3
A or B
A= $mode eq "semi"B= $mode eq "approx"
ABresult
1X1
011
000
3297  
3298 # Calculate the number of weeks/days apart (temporarily ignoring
3299 # DST effects).
3300  
3301 88 $dd = $dmb->days_since_1BC($date2) -
3302 $dmb->days_since_1BC($date1);
3303 88 $dw = int($dd/7);
3304 88 $dd -= $dw*7;
3305  
3306 # Adding $dd to $date1 gives: ($y2,$m2,$d2, $h1,$mn1,$s1)
3307 # Make sure this is valid (taking into account DST effects).
3308 # If it isn't, make it valid.
3309  
3310 88 ▶ if ($dw || $dd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dw or $dd) 69 19 88
Condition100%3/3
$dw or $dd
l!l&&r!l&&!r
96019
MC/DC100%2/2
$dw or $dd
$dw $dd
Truth table100%3/3
A or B
A= $dwB= $dd
ABresult
1X1
011
000
3311 69 my($y1,$m1,$d1,$h1,$mn1,$s1) = @$date1;
3312 69 my($y2,$m2,$d2,$h2,$mn2,$s2) = @$date2;
3313 69 $date1 = [$y2,$m2,$d2,$h1,$mn1,$s1];
3314 }
3315 88 ▶ if ($dy || $dm || $dw || $dd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dy or $dm or $dw or $dd) 81 7 88
Condition100%9/9
$dy or $dm or $dw or $dd
l!l&&r!l&&!r
65167
$dy or $dm or $dw
l!l&&r!l&&!r
56923
$dy or $dm
l!l&&r!l&&!r
441232
MC/DC100%4/4
$dy or $dm or $dw or $dd
$dy $dm $dw $dd
Truth table100%5/5
A or B or C or D
A= $dyB= $dmC= $dwD= $dd
ABCDresult
1XXX1
01XX1
001X1
00011
00000
3316 81 ▶ my $force = ( ($dw > 0 || $dd > 0) ? 1 : -1 );
Branch: 1 branch
BranchTrueFalseTotal
$dw > 0 || $dd > 0 ? : 39 42 81
Condition100%3/3
$dw > 0 or $dd > 0
l!l&&r!l&&!r
73242
MC/DC100%2/2
$dw > 0 or $dd > 0
$dw > 0 $dd > 0
Truth table100%3/3
A or B
A= $dw > 0B= $dd > 0
ABresult
1X1
011
000
3317 81 my($off,$isdst,$abb);
3318 81 ($date1,$off,$isdst,$abb) =
3319 $self->_calc_date_check_dst($date1,$tz2,$isdst2,$force);
3320 }
3321 }
3322  
3323 1430 ▶ if ($mode eq 'bsemi' || $mode eq 'bapprox') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "bsemi" or $mode eq "bapprox") 94 1336 1430
Condition100%3/3
$mode eq "bsemi" or $mode eq "bapprox"
l!l&&r!l&&!r
50441336
MC/DC100%2/2
$mode eq "bsemi" or $mode eq "bapprox"
$mode eq "bsemi" $mode eq "bapprox"
Truth table100%3/3
A or B
A= $mode eq "bsemi"B= $mode eq "bapprox"
ABresult
1X1
011
000
3324 # Calculate the number of weeks. Ignore the days
3325 # part. Also, since there are no DST effects, we don't
3326 # have to check for validity.
3327  
3328 94 $dd = $dmb->days_since_1BC($date2) -
3329 $dmb->days_since_1BC($date1);
3330 94 $dw = int($dd/7);
3331 94 $dd = 0;
3332 94 $date1 = $dmb->calc_date_days($date1,$dw*7);
3333 }
3334  
3335 1430 ▶ if ($mode eq 'exact' || $mode eq 'semi' || $mode eq 'approx') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "exact" or $mode eq "semi" or $mode eq "approx") 1274 156 1430
Condition100%6/6
$mode eq "exact" or $mode eq "semi" or $mode eq "approx"
l!l&&r!l&&!r
120668156
$mode eq "exact" or $mode eq "semi"
l!l&&r!l&&!r
118620224
MC/DC100%3/3
$mode eq "exact" or $mode eq "semi" or $mode eq "approx"
$mode eq "exact" $mode eq "semi" $mode eq "approx"
Truth table100%4/4
A or B or C
A= $mode eq "exact"B= $mode eq "semi"C= $mode eq "approx"
ABCresult
1XX1
01X1
0011
0000
3336 1274 my $sec1 = $dmb->secs_since_1970($date1);
3337 1274 my $sec2 = $dmb->secs_since_1970($date2);
3338 1274 $ds = $sec2 - $sec1;
3339  
3340 {
3341 170 ▶ no integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
3342 1274 $dh = int($ds/3600);
3343 1274 $ds -= $dh*3600;
3344 }
3345 1274 $dmn = int($ds/60);
3346 1274 $ds -= $dmn*60;
3347 }
3348  
3349 1430 ▶ if ($mode eq 'business' || $mode eq 'bsemi' || $mode eq 'bapprox') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "business" or $mode eq "bsemi" or $mode eq "bapprox") 156 1274 1430
Condition100%6/6
$mode eq "business" or $mode eq "bsemi" or $mode eq "bapprox"
l!l&&r!l&&!r
112441274
$mode eq "business" or $mode eq "bsemi"
l!l&&r!l&&!r
62501318
MC/DC100%3/3
$mode eq "business" or $mode eq "bsemi" or $mode eq "bapprox"
$mode eq "business" $mode eq "bsemi" $mode eq "bapprox"
Truth table100%4/4
A or B or C
A= $mode eq "business"B= $mode eq "bsemi"C= $mode eq "bapprox"
ABCresult
1XX1
01X1
0011
0000
3350  
3351 # Make sure both are work days
3352  
3353 156 $date1 = $self->__nextprev_business_day(0,0,1,$date1);
3354 156 $date2 = $self->__nextprev_business_day(0,0,1,$date2);
3355  
3356 156 my($y1,$m1,$d1,$h1,$mn1,$s1) = @$date1;
3357 156 my($y2,$m2,$d2,$h2,$mn2,$s2) = @$date2;
3358  
3359 # Find out which direction we need to move $date1 to get to $date2
3360  
3361 156 my $dir = 0;
3362 156 ▶ if ($y1 < $y2) {
Branch: 6 branches
BranchTrueFalseTotal
if ($y1 < $y2) { } 2 154 156
elsif ($y1 > $y2) { } 3 151 154
elsif ($m1 < $m2) { } 2 149 151
elsif ($m1 > $m2) { } 3 146 149
elsif ($d1 < $d2) { } 73 73 146
elsif ($d1 > $d2) { } 33 40 73
3363 2 $dir = 1;
3364 } elsif ($y1 > $y2) {
3365 3 $dir = -1;
3366 } elsif ($m1 < $m2) {
3367 2 $dir = 1;
3368 } elsif ($m1 > $m2) {
3369 3 $dir = -1;
3370 } elsif ($d1 < $d2) {
3371 73 $dir = 1;
3372 } elsif ($d1 > $d2) {
3373 33 $dir = -1;
3374 }
3375  
3376 # Now do the day part (to get to the same day)
3377  
3378 156 $dd = 0;
3379 156 ▶ while ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) 456 156 612
3380 456 ($y1,$m1,$d1) = @{ $dmb->calc_date_days([$y1,$m1,$d1],$dir) };
3381 456 ▶ $dd += $dir if ($self->__is_business_day([$y1,$m1,$d1,0,0,0],0));
Branch: 1 branch
BranchTrueFalseTotal
if $self->__is_business_day([$y1, $m1, $d1, 0, 0, 0], 0) 297 159 456
3382 456 ▶ $dir = 0 if ($y1 == $y2 && $m1 == $m2 && $d1 == $d2);
Branch: 1 branch
BranchTrueFalseTotal
if $y1 == $y2 and $m1 == $m2 and $d1 == $d2 116 340 456
Condition100%6/6
$y1 == $y2 and $m1 == $m2 and $d1 == $d2
!ll&&!rl&&r
77263116
$y1 == $y2 and $m1 == $m2
!ll&&!rl&&r
1760379
MC/DC100%3/3
$y1 == $y2 and $m1 == $m2 and $d1 == $d2
$y1 == $y2 $m1 == $m2 $d1 == $d2
Truth table100%4/4
A and B and C
A= $y1 == $y2B= $m1 == $m2C= $d1 == $d2
ABCresult
0XX0
10X0
1100
1111
3383 }
3384  
3385 # Both dates are now on a business day, and during business
3386 # hours, so do the hr/min/sec part trivially
3387  
3388 156 $dh = $h2-$h1;
3389 156 $dmn = $mn2-$mn1;
3390 156 $ds = $s2-$s1;
3391 }
3392  
3393 1430 return [ $dy,$dm,$dw,$dd,$dh,$dmn,$ds ];
3394 }
3395  
3396 170 ▶no integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
3397 3178 ▶sub _calc_date_delta {
Subroutine _calc_date_delta: called CC=17 SCAR=29.7
3398 3178 my($self,$delta,$subtract) = @_;
3399 3178 my $ret = $self->new_date();
3400  
3401 3178 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 3178 3178
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
003178
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
3402 0 $$ret{'err'} = '[calc] Date object invalid';
3403 0 return $ret;
3404 }
3405  
3406 3178 ▶ if ($$delta{'err'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delta->{"err"}) 0 3178 3178
3407 0 $$ret{'err'} = '[calc] Delta object invalid';
3408 0 return $ret;
3409 }
3410  
3411 # Get the date/delta fields
3412  
3413 3178 ▶ $subtract = 0 if (! $subtract);
Branch: 1 branch
BranchTrueFalseTotal
unless $subtract 1942 1236 3178
3414 3178 my @delta = @{ $$delta{'data'}{'delta'} };
3415 3178 my @date = @{ $$self{'data'}{'date'} };
3416 3178 ▶ my $business = ($$delta{'data'}{'mode'} eq 'business' ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$delta->{'data'}{'mode'} eq 'business' ? : 75 3103 3178
3417 3178 my $tz = $$self{'data'}{'tz'};
3418 3178 my $isdst = $$self{'data'}{'isdst'};
3419  
3420 # We can't handle a delta longer than 10000 years
3421 3178 my($dy,$dm,$dw,$dd,$dh,$dmn,$ds) = @delta;
3422 3178 ▶ if (abs($dy) > 10000 ||
Branch: 1 branch
BranchTrueFalseTotal
if (abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000 or abs $dd > 3660000 or abs $dh > 87840000 or abs $dmn > 5270400000 or abs $ds > '316224000000') 2 3176 3178
Condition66%12/18
abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000 or abs $dd > 3660000 or abs $dh > 87840000 or abs $dmn > 5270400000 or abs $ds > '316224000000'
l!l&&r!l&&!r
203176
abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000 or abs $dd > 3660000 or abs $dh > 87840000 or abs $dmn > 5270400000
l!l&&r!l&&!r
203176
abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000 or abs $dd > 3660000 or abs $dh > 87840000
l!l&&r!l&&!r
113176
abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000 or abs $dd > 3660000
l!l&&r!l&&!r
103177
abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000
l!l&&r!l&&!r
013177
abs $dy > 10000 or abs $dm > 120000
l!l&&r!l&&!r
003178
MC/DC28%2/7
abs $dy > 10000 or abs $dm > 120000 or abs $dw > 530000 or abs $dd > 3660000 or abs $dh > 87840000 or abs $dmn > 5270400000 or abs $ds > '316224000000'
abs $dy > 10000 abs $dm > 120000 abs $dw > 530000 abs $dd > 3660000 abs $dh > 87840000 abs $dmn > 5270400000 abs $ds > '316224000000'
Truth table37%3/8
A or B or C or D or E or F or G
A= abs $dy > 10000B= abs $dm > 120000C= abs $dw > 530000D= abs $dd > 3660000E= abs $dh > 87840000F= abs $dmn > 5270400000G= abs $ds > '316224000000'
ABCDEFGresult
1XXXXXX1
01XXXXX1
001XXXX1
0001XXX1
00001XX1
000001X1
00000011
00000000
3423 abs($dm) > 120000 || # 10000*12
3424 abs($dw) > 530000 || # 10000*53
3425 abs($dd) > 3660000 || # 10000*366
3426 abs($dh) > 87840000 || # 10000*366*24
3427 abs($dmn) > 5270400000 || # 10000*366*24*60
3428 abs($ds) > 316224000000) { # 10000*366*24*60*60
3429 2 $$ret{'err'} = '[calc] Delta too large';
3430 2 return $ret;
3431 }
3432  
3433 3176 my($err,$date2,$offset,$abbrev);
3434 3176 ($err,$date2,$offset,$isdst,$abbrev) =
3435 $self->__calc_date_delta([@date],[@delta],$subtract,$business,$tz,$isdst);
3436  
3437 3176 ▶ if (ref($date2) eq 'ARRAY' && ($$date2[0]<0 || $$date2[0]>9999)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $date2 eq 'ARRAY' and $date2->[0] < 0 || $date2->[0] > 9999) { } 1 3175 3176
elsif ($err) { } 2 3173 3175
Condition83%5/6
ref $date2 eq "ARRAY" and $date2->[0] < 0 || $date2->[0] > 9999
!ll&&!rl&&r
231731
$date2->[0] < 0 or $date2->[0] > 9999
l!l&&r!l&&!r
013173
MC/DC66%2/3
ref $date2 eq "ARRAY" and $date2->[0] < 0 || $date2->[0] > 9999
ref $date2 eq "ARRAY" $date2->[0] < 0 $date2->[0] > 9999
Truth table75%3/4
A and B or C
A= ref $date2 eq "ARRAY"B= $date2->[0] < 0C= $date2->[0] > 9999
ABCresult
0XX0
1000
11X1
1011
3438 1 $$ret{'err'} = '[calc] Delta produces date outside valid range';
3439 } elsif ($err) {
3440 2 $$ret{'err'} = '[calc] Unable to perform calculation';
3441 } else {
3442 3173 $$ret{'data'}{'set'} = 1;
3443 3173 $$ret{'data'}{'date'} = $date2;
3444 3173 $$ret{'data'}{'tz'} = $tz;
3445 3173 $$ret{'data'}{'isdst'} = $isdst;
3446 3173 $$ret{'data'}{'offset'}= $offset;
3447 3173 $$ret{'data'}{'abb'} = $abbrev;
3448 }
3449 3176 return $ret;
3450 }
3451 170 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
3452  
3453 3308 ▶sub __calc_date_delta {
Subroutine __calc_date_delta: called CC=21 SCAR=30.5
3454 3308 my($self,$date,$delta,$subtract,$business,$tz,$isdst) = @_;
3455  
3456 3308 my ($dy,$dm,$dw,$dd,$dh,$dmn,$ds) = @$delta;
3457 3308 my @date = @$date;
3458  
3459 3308 my ($err,$date2,$offset,$abbrev);
3460  
3461 # In business mode, daylight saving time is ignored, so days are
3462 # of a constant, known length, so they'll be done in the exact
3463 # function. Otherwise, they'll be done in the approximate function.
3464 #
3465 # Also in business mode, if $subtract = 2, then the starting date
3466 # must be a business date or an error occurs.
3467  
3468 3308 my($dd_exact,$dd_approx);
3469 3308 ▶ if ($business) {
Branch: 1 branch
BranchTrueFalseTotal
if ($business) { } 75 3233 3308
3470 75 $dd_exact = $dd;
3471 75 $dd_approx = 0;
3472  
3473 75 ▶ if ($subtract == 2 && ! $self->__is_business_day($date,1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subtract == 2 and not $self->__is_business_day($date, 1)) 2 73 75
Condition66%2/3
$subtract == 2 and not $self->__is_business_day($date, 1)
!ll&&!rl&&r
7302
MC/DC50%1/2
$subtract == 2 and not $self->__is_business_day($date, 1)
$subtract == 2 not $self->__is_business_day($date, 1)
Truth table66%2/3
A and not(B)
A= $subtract == 2B= not $self->__is_business_day($date, 1)
ABresult
0X0
100
111
3474 2 return (1);
3475 }
3476  
3477 } else {
3478 3233 $dd_exact = 0;
3479 3233 $dd_approx = $dd;
3480 }
3481  
3482 3306 ▶ if ($subtract == 2 && ($dy || $dm || $dw || $dd_approx)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subtract == 2 and $dy || $dm || $dw || $dd_approx) { } 1198 2108 3306
Condition100%12/12
$subtract == 2 and $dy || $dm || $dw || $dd_approx
!ll&&!rl&&r
2097111198
$dy or $dm or $dw or $dd_approx
l!l&&r!l&&!r
11702811
$dy or $dm or $dw
l!l&&r!l&&!r
11472339
$dy or $dm
l!l&&r!l&&!r
10885962
MC/DC100%5/5
$subtract == 2 and $dy || $dm || $dw || $dd_approx
$subtract == 2 $dy $dm $dw $dd_approx
Truth table100%6/6
A and B or C or D or E
A= $subtract == 2B= $dyC= $dmD= $dwE= $dd_approx
ABCDEresult
0XXXX0
100000
11XXX1
101XX1
1001X1
100011
3483 # For subtract=2:
3484 # DATE = RET + DELTA
3485 #
3486 # The delta consisists of an approximate part (which is added first)
3487 # and an exact part (added second):
3488 # DATE = RET + DELTA(approx) + DELTA(exact)
3489 # DATE = RET' + DELTA(exact)
3490 # where RET' = RET + DELTA(approx)
3491 #
3492 # For an exact delta, subtract==2 and subtract==1 are equivalent,
3493 # so this can be written:
3494 # DATE - DELTA(exact) = RET'
3495 #
3496 # So the inverse subtract only needs to include the approximate
3497 # portion of the delta.
3498  
3499 1198 ($err,$date2,$offset,$isdst,$abbrev) =
3500 $self->__calc_date_delta_exact([@date],[-1*$dd_exact,-1*$dh,-1*$dmn,-1*$ds],
3501 $business,$tz,$isdst);
3502  
3503 1198 ▶ ($err,$date2,$offset,$isdst,$abbrev) =
Branch: 1 branch
BranchTrueFalseTotal
unless $err 1198 0 1198
3504 $self->__calc_date_delta_inverse($date2,[$dy,$dm,$dw,$dd_approx],
3505 $business,$tz,$isdst)
3506 if (! $err);
3507  
3508 } else {
3509 # We'll add the approximate part, followed by the exact part.
3510 # After the approximate part, we need to make sure we're on
3511 # a valid business day in business mode.
3512  
3513 ($dy,$dm,$dw,$dd_exact,$dd_approx,$dh,$dmn,$ds) =
3514 2108 ▶ map { -1*$_ } ($dy,$dm,$dw,$dd_exact,$dd_approx,$dh,$dmn,$ds)
Branch: 1 branch
BranchTrueFalseTotal
if $subtract 36 2072 2108
3515 if ($subtract);
3516 2108 @$date2 = @date;
3517  
3518 2108 ▶ if ($dy || $dm || $dw || $dd) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dy or $dm or $dw or $dd) { } 1867 241 2108
elsif ($business) { } 48 193 241
Condition100%9/9
$dy or $dm or $dw or $dd
l!l&&r!l&&!r
1742125241
$dy or $dm or $dw
l!l&&r!l&&!r
165290366
$dy or $dm
l!l&&r!l&&!r
1411241456
MC/DC100%4/4
$dy or $dm or $dw or $dd
$dy $dm $dw $dd
Truth table100%5/5
A or B or C or D
A= $dyB= $dmC= $dwD= $dd
ABCDresult
1XXX1
01XX1
001X1
00011
00000
3519 1867 ($err,$date2,$offset,$isdst,$abbrev) =
3520 $self->__calc_date_delta_approx($date2,[$dy,$dm,$dw,$dd_approx],
3521 $business,$tz,$isdst);
3522 } elsif ($business) {
3523 48 $date2 = $self->__nextprev_business_day(0,0,1,$date2);
3524 }
3525  
3526 2108 ▶ ($err,$date2,$offset,$isdst,$abbrev) =
Branch: 1 branch
BranchTrueFalseTotal
if not $err and $dd_exact || $dh || $dmn || $ds 268 1840 2108
Condition91%11/12
not $err and $dd_exact || $dh || $dmn || $ds
!ll&&!rl&&r
01840268
$dd_exact or $dh or $dmn or $ds
l!l&&r!l&&!r
233351840
$dd_exact or $dh or $dmn
l!l&&r!l&&!r
214191875
$dd_exact or $dh
l!l&&r!l&&!r
201941894
MC/DC80%4/5
not $err and $dd_exact || $dh || $dmn || $ds
not $err $dd_exact $dh $dmn $ds
Truth table83%5/6
not(A) and B or C or D or E
A= not $errB= $dd_exactC= $dhD= $dmnE= $ds
ABCDEresult
0XXXX0
100000
11XXX1
101XX1
1001X1
100011
3527 $self->__calc_date_delta_exact($date2,[$dd_exact,$dh,$dmn,$ds],
3528 $business,$tz,$isdst)
3529 if (! $err && ($dd_exact || $dh || $dmn || $ds));
3530 }
3531  
3532 3306 return($err,$date2,$offset,$isdst,$abbrev);
3533 }
3534  
3535 # Do the inverse part of a calculation.
3536 #
3537 # $delta = [$dy,$dm,$dw,$dd]
3538 #
3539 1198 ▶sub __calc_date_delta_inverse {
Subroutine __calc_date_delta_inverse: called CC=15 SCAR=38.6
3540 1198 my($self,$date,$delta,$business,$tz,$isdst) = @_;
3541 1198 my $dmt = $$self{'tz'};
3542 1198 my $dmb = $$dmt{'base'};
3543 1198 my @date2;
3544  
3545 # Given: DATE1, DELTA
3546 # Find: DATE2
3547 # where DATE2 + DELTA = DATE1
3548 #
3549 # Start with:
3550 # DATE2 = DATE1 - DELTA
3551 #
3552 # if (DATE2+DELTA < DATE1)
3553 # while (1)
3554 # DATE2 = DATE2 + 1 day
3555 # if DATE2+DELTA < DATE1
3556 # next
3557 # elsif DATE2+DELTA > DATE1
3558 # return ERROR
3559 # else
3560 # return DATE2
3561 # done
3562 #
3563 # elsif (DATE2+DELTA > DATE1)
3564 # while (1)
3565 # DATE2 = DATE2 - 1 day
3566 # if DATE2+DELTA > DATE1
3567 # next
3568 # elsif DATE2+DELTA < DATE1
3569 # return ERROR
3570 # else
3571 # return DATE2
3572 # done
3573 #
3574 # else
3575 # return DATE2
3576  
3577 1198 ▶ if ($business) {
Branch: 1 branch
BranchTrueFalseTotal
if ($business) { } 0 1198 1198
3578  
3579 0 my $date1 = $date;
3580 0 my ($err,$date2,$off,$isd,$abb,@del,$tmp,$cmp);
3581 0 @del = map { $_*-1 } @$delta;
3582  
3583 0 ($err,$date2,$off,$isd,$abb) =
3584 $self->__calc_date_delta_approx($date,[@del],$business,$tz,$isdst);
3585  
3586 0 ($err,$tmp,$off,$isd,$abb) =
3587 $self->__calc_date_delta_approx($date2,$delta,$business,$tz,$isdst);
3588  
3589 0 $cmp = $self->_cmp_date($tmp,$date1);
3590  
3591 0 ▶ if ($cmp < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmp < 0) { } 0 0 0
elsif ($cmp > 0) { } 0 0 0
3592 0 while (1) {
3593 0 $date2 = $self->__nextprev_business_day(0,1,0,$date2);
3594 0 ($err,$tmp,$off,$isd,$abb) =
3595 $self->__calc_date_delta_approx($date2,$delta,$business,$tz,$isdst);
3596 0 $cmp = $self->_cmp_date($tmp,$date1);
3597 0 ▶ if ($cmp < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmp < 0) { } 0 0 0
elsif ($cmp > 0) { } 0 0 0
3598 0 next;
3599 } elsif ($cmp > 0) {
3600 0 return (1);
3601 } else {
3602 0 last;
3603 }
3604 }
3605  
3606 } elsif ($cmp > 0) {
3607 0 while (1) {
3608 0 $date2 = $self->__nextprev_business_day(1,1,0,$date2);
3609 0 ($err,$tmp,$off,$isd,$abb) =
3610 $self->__calc_date_delta_approx($date2,$delta,$business,$tz,$isdst);
3611 0 $cmp = $self->_cmp_date($tmp,$date1);
3612 0 ▶ if ($cmp > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmp > 0) { } 0 0 0
elsif ($cmp < 0) { } 0 0 0
3613 0 next;
3614 } elsif ($cmp < 0) {
3615 0 return (1);
3616 } else {
3617 0 last;
3618 }
3619 }
3620 }
3621  
3622 0 @date2 = @$date2;
3623  
3624 } else {
3625  
3626 1198 my @tmp = @$date[0..2]; # [y,m,d]
3627 1198 my @hms = @$date[3..5]; # [h,m,s]
3628 1198 my $date1 = [@tmp];
3629  
3630 1198 my $date2 = $dmb->_calc_date_ymwd($date1,$delta,1);
3631 1198 my $tmp = $dmb->_calc_date_ymwd($date2,$delta);
3632 1198 my $cmp = $self->_cmp_date($tmp,$date1);
3633  
3634 1198 ▶ if ($cmp < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmp < 0) { } 8 1190 1198
elsif ($cmp > 0) { } 2 1188 1190
3635 8 while (1) {
3636 9 $date2 = $dmb->calc_date_days($date2,1);
3637 9 $tmp = $dmb->_calc_date_ymwd($date2,$delta);
3638 9 $cmp = $self->_cmp_date($tmp,$date1);
3639 9 ▶ if ($cmp < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmp < 0) { } 1 8 9
elsif ($cmp > 0) { } 0 8 8
3640 1 next;
3641 } elsif ($cmp > 0) {
3642 0 return (1);
3643 } else {
3644 8 last;
3645 }
3646 }
3647  
3648 } elsif ($cmp > 0) {
3649 2 while (1) {
3650 2 $date2 = $dmb->calc_date_days($date2,-1);
3651 2 $tmp = $dmb->_calc_date_ymwd($date2,$delta);
3652 2 $cmp = $self->_cmp_date($tmp,$date1);
3653 2 ▶ if ($cmp > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmp > 0) { } 0 2 2
elsif ($cmp < 0) { } 0 2 2
3654 0 next;
3655 } elsif ($cmp < 0) {
3656 0 return (1);
3657 } else {
3658 2 last;
3659 }
3660 }
3661 }
3662  
3663 1198 @date2 = (@$date2,@hms);
3664 }
3665  
3666 # Make sure DATE2 is valid (within DST constraints) and
3667 # return it.
3668  
3669 1198 my($date2,$abb,$off,$err);
3670 1198 ($date2,$off,$isdst,$abb) = $self->_calc_date_check_dst([@date2],$tz,$isdst,0);
3671  
3672 1198 ▶ return (1) if (! defined($date2));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date2 0 1198 1198
3673 1198 return (0,$date2,$off,$isdst,$abb);
3674 }
3675  
3676 1209 ▶sub _cmp_date {
Subroutine _cmp_date: called CC=3 SCAR=11.0
3677 1209 my($self,$date0,$date1) = @_;
3678 1209 ▶ return ($$date0[0] <=> $$date1[0] ||
Condition83%5/6
$date0->[0] <=> $date1->[0] || $date0->[1] <=> $date1->[1] || $date0->[2] <=> $date1->[2]
l!l&&r!l&&!r
291198
$date0->[0] <=> $date1->[0] or $date0->[1] <=> $date1->[1]
l!l&&r!l&&!r
201207
MC/DC66%2/3
$date0->[0] <=> $date1->[0] || $date0->[1] <=> $date1->[1] || $date0->[2] <=> $date1->[2]
$date0->[0] <=> $date1->[0] $date0->[1] <=> $date1->[1] $date0->[2] <=> $date1->[2]
Truth table75%3/4
A or B || C
A= $date0->[0] <=> $date1->[0]B= $date0->[1] <=> $date1->[1]C= $date0->[2] <=> $date1->[2]
ABCresult
1XX1
01X1
0011
0000
3679 $$date0[1] <=> $$date1[1] ||
3680 $$date0[2] <=> $$date1[2]);
3681 }
3682  
3683 # Do the approximate part of a calculation.
3684 #
3685 1867 ▶sub __calc_date_delta_approx {
Subroutine __calc_date_delta_approx: called CC=11 SCAR=24.0
3686 1867 my($self,$date,$delta,$business,$tz,$isdst) = @_;
3687  
3688 1867 my $dmt = $$self{'tz'};
3689 1867 my $dmb = $$dmt{'base'};
3690 1867 my($y,$m,$d,$h,$mn,$s) = @$date;
3691 1867 my($dy,$dm,$dw,$dd) = @$delta;
3692  
3693 #
3694 # Do the year/month part.
3695 #
3696 # If we are past the last day of a month, move the date back to
3697 # the last day of the month. i.e. Jan 31 + 1 month = Feb 28.
3698 #
3699  
3700 1867 ▶ $y += $dy if ($dy);
Branch: 1 branch
BranchTrueFalseTotal
if $dy 1411 456 1867
3701 1867 ▶ $dmb->_mod_add(-12,$dm,\$m,\$y) # -12 means 1-12 instead of 0-11
Branch: 1 branch
BranchTrueFalseTotal
if $dm 384 1483 1867
3702 if ($dm);
3703  
3704 1867 my $dim = $dmb->days_in_month($y,$m);
3705 1867 ▶ $d = $dim if ($d > $dim);
Branch: 1 branch
BranchTrueFalseTotal
if $d > $dim 1 1866 1867
3706  
3707 #
3708 # Do the week part.
3709 #
3710 # The week is treated as 7 days for both business and non-business
3711 # calculations.
3712 #
3713 # In a business calculation, make sure we're on a business date.
3714 #
3715  
3716 1867 ▶ if ($business) {
Branch: 1 branch
BranchTrueFalseTotal
if ($business) { } 25 1842 1867
3717 25 ▶ ($y,$m,$d) = @{ $dmb->calc_date_days([$y,$m,$d],$dw*7) } if ($dw);
Branch: 1 branch
BranchTrueFalseTotal
if $dw 5 20 25
3718 ($y,$m,$d,$h,$mn,$s) =
3719 25 @{ $self->__nextprev_business_day(0,0,1,[$y,$m,$d,$h,$mn,$s]) };
3720 } else {
3721 1842 $dd += $dw*7;
3722 }
3723  
3724 #
3725 # Now do the day part. $dd is always 0 in business calculations.
3726 #
3727  
3728 1867 ▶ if ($dd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dd) 267 1600 1867
3729 267 ($y,$m,$d) = @{ $dmb->calc_date_days([$y,$m,$d],$dd) };
3730 }
3731  
3732 #
3733 # At this point, we need to make sure that we're a valid date
3734 # (within the constraints of DST).
3735 #
3736 # If it is not valid in this offset, try the other one. If neither
3737 # works, then we want the the date to be 24 hours later than the
3738 # previous day at this time (if $dd > 0) or 24 hours earlier than
3739 # the next day at this time (if $dd < 0). We'll use the 24 hour
3740 # definition even for business days, but then we'll double check
3741 # that the resulting date is a business date.
3742 #
3743  
3744 1867 ▶ my $force = ( ($dd > 0 || $dw > 0 || $dm > 0 || $dy > 0) ? 1 : -1 );
Branch: 1 branch
BranchTrueFalseTotal
$dd > 0 || $dw > 0 || $dm > 0 || $dy > 0 ? : 1784 83 1867
Condition100%9/9
$dd > 0 or $dw > 0 or $dm > 0 or $dy > 0
l!l&&r!l&&!r
530125483
$dd > 0 or $dw > 0 or $dm > 0
l!l&&r!l&&!r
2243061337
$dd > 0 or $dw > 0
l!l&&r!l&&!r
22131643
MC/DC100%4/4
$dd > 0 or $dw > 0 or $dm > 0 or $dy > 0
$dd > 0 $dw > 0 $dm > 0 $dy > 0
Truth table100%5/5
A or B or C or D
A= $dd > 0B= $dw > 0C= $dm > 0D= $dy > 0
ABCDresult
1XXX1
01XX1
001X1
00011
00000
3745 1867 my($off,$abb);
3746 1867 ($date,$off,$isdst,$abb) =
3747 $self->_calc_date_check_dst([$y,$m,$d,$h,$mn,$s],$tz,$isdst,$force);
3748 1867 return (0,$date,$off,$isdst,$abb);
3749 }
3750  
3751 # Do the exact part of a calculation.
3752 #
3753 1466 ▶sub __calc_date_delta_exact {
Subroutine __calc_date_delta_exact: called CC=27 SCAR=33.2
3754 1466 my($self,$date,$delta,$business,$tz,$isdst) = @_;
3755 1466 my $dmt = $$self{'tz'};
3756 1466 my $dmb = $$dmt{'base'};
3757  
3758 1466 ▶ if ($business) {
Branch: 1 branch
BranchTrueFalseTotal
if ($business) { } 68 1398 1466
3759  
3760 # Simplify hours/minutes/seconds where the day length is defined
3761 # by the start/end of the business day.
3762  
3763 68 my ($dd,$dh,$dmn,$ds) = @$delta;
3764 68 my ($y,$m,$d,$h,$mn,$s)= @$date;
3765 68 my ($hbeg,$mbeg,$sbeg) = @{ $$dmb{'data'}{'calc'}{'workdaybeg'} };
3766 68 my ($hend,$mend,$send) = @{ $$dmb{'data'}{'calc'}{'workdayend'} };
3767 68 my $bdlen = $$dmb{'data'}{'len'}{'bdlength'};
3768  
3769 170 ▶ no integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
3770 68 my $tmp;
3771 68 $ds += $dh*3600 + $dmn*60;
3772 68 $tmp = int($ds/$bdlen);
3773 68 $dd += $tmp;
3774 68 $ds -= $tmp*$bdlen;
3775 68 $dh = int($ds/3600);
3776 68 $ds -= $dh*3600;
3777 68 $dmn = int($ds/60);
3778 68 $ds -= $dmn*60;
3779 170 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
3780  
3781 68 ▶ if ($dd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dd) 20 48 68
3782 20 my $prev = 0;
3783 20 ▶ if ($dd < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dd < 1) 4 16 20
3784 4 $prev = 1;
3785 4 $dd *= -1;
3786 }
3787  
3788 ($y,$m,$d,$h,$mn,$s) =
3789 20 @{ $self->__nextprev_business_day($prev,$dd,0,[$y,$m,$d,$h,$mn,$s]) };
3790 }
3791  
3792 # At this point, we're adding less than a day for the
3793 # hours/minutes/seconds part AND we know that the current
3794 # day is during business hours.
3795 #
3796 # We'll add them (without affecting days... we'll need to
3797 # test things by hand to make sure we should or shouldn't
3798 # do that.
3799  
3800 68 $dmb->_mod_add(60,$ds,\$s,\$mn);
3801 68 $dmb->_mod_add(60,$dmn,\$mn,\$h);
3802 68 $h += $dh;
3803 # Note: it's possible that $h > 23 at this point or $h < 0
3804  
3805 68 ▶ if ($h > $hend ||
Branch: 2 branches
BranchTrueFalseTotal
if ($h > $hend or $h == $hend and $mn > $mend or $h == $hend and $mn == $mend and $s > $send or $h == $hend and $mn == $mend and $s == $send) { } 20 48 68
elsif ($h < $hbeg or $h == $hbeg and $mn < $mbeg or $h == $hbeg and $mn == $mbeg and $s < $sbeg) { } 15 63 78
Condition79%19/24
$h > $hend or $h == $hend and $mn > $mend or $h == $hend and $mn == $mend and $s > $send or $h == $hend and $mn == $mend and $s == $send
l!l&&r!l&&!r
101048
$h > $hend or $h == $hend and $mn > $mend or $h == $hend and $mn == $mend and $s > $send
l!l&&r!l&&!r
10058
$h > $hend or $h == $hend and $mn > $mend
l!l&&r!l&&!r
10058
$h == $hend and $mn > $mend
!ll&&!rl&&r
45130
$h == $hend and $mn == $mend and $s > $send
!ll&&!rl&&r
48100
$h == $hend and $mn == $mend
!ll&&!rl&&r
45310
$h == $hend and $mn == $mend and $s == $send
!ll&&!rl&&r
48010
$h == $hend and $mn == $mend
!ll&&!rl&&r
45310
MC/DC66%6/9
$h > $hend or $h == $hend and $mn > $mend or $h == $hend and $mn == $mend and $s > $send or $h == $hend and $mn == $mend and $s == $send
$h > $hend $h == $hend $mn > $mend $h == $hend $mn == $mend $s > $send $h == $hend $mn == $mend $s == $send
Truth table14%4/28
A or B and C or D and E and F or G and H and I
A= $h > $hendB= $h == $hendC= $mn > $mendD= $h == $hendE= $mn == $mendF= $s > $sendG= $h == $hendH= $mn == $mendI= $s == $send
ABCDEFGHIresult
1XXXXXXXX1
011XXXXXX1
00X111XXX1
010111XXX1
00X0XX1111
00X10X1111
00X1101111
0100XX1111
01010X1111
0101101111
00X0XX0XX0
00X0XX10X0
00X0XX1100
00X10X0XX0
00X10X10X0
00X10X1100
00X1100XX0
00X11010X0
00X1101100
0100XX0XX0
0100XX10X0
0100XX1100
01010X0XX0
01010X10X0
01010X1100
0101100XX0
01011010X0
0101101100
3806 ($h == $hend && $mn > $mend) ||
3807 ($h == $hend && $mn == $mend && $s > $send) ||
3808 ($h == $hend && $mn == $mend && $s == $send)) {
3809  
3810 # We've gone past the end of the business day.
3811  
3812 20 my $t2 = $dmb->calc_time_time([$h,$mn,$s],[$hend,$mend,$send],1);
3813  
3814 20 while (1) {
3815 26 ($y,$m,$d) = @{ $dmb->calc_date_days([$y,$m,$d],1) };
3816 26 ▶ last if ($self->__is_business_day([$y,$m,$d,$h,$mn,$s]));
Branch: 1 branch
BranchTrueFalseTotal
if $self->__is_business_day([$y, $m, $d, $h, $mn, $s]) 20 6 26
3817 }
3818  
3819 20 ($h,$mn,$s) = @{ $dmb->calc_time_time([$hbeg,$mbeg,$sbeg],$t2) };
3820  
3821 ▶ } elsif ($h < $hbeg ||
Condition66%10/15
$h < $hbeg or $h == $hbeg and $mn < $mbeg or $h == $hbeg and $mn == $mbeg and $s < $sbeg
l!l&&r!l&&!r
15033
$h < $hbeg or $h == $hbeg and $mn < $mbeg
l!l&&r!l&&!r
15033
$h == $hbeg and $mn < $mbeg
!ll&&!rl&&r
3030
$h == $hbeg and $mn == $mbeg and $s < $sbeg
!ll&&!rl&&r
3030
$h == $hbeg and $mn == $mbeg
!ll&&!rl&&r
3003
MC/DC16%1/6
$h < $hbeg or $h == $hbeg and $mn < $mbeg or $h == $hbeg and $mn == $mbeg and $s < $sbeg
$h < $hbeg $h == $hbeg $mn < $mbeg $h == $hbeg $mn == $mbeg $s < $sbeg
Truth table30%3/10
A or B and C or D and E and F
A= $h < $hbegB= $h == $hbegC= $mn < $mbegD= $h == $hbegE= $mn == $mbegF= $s < $sbeg
ABCDEFresult
1XXXXX1
011XXX1
00X1111
0101111
00X0XX0
00X10X0
00X1100
0100XX0
01010X0
0101100
3822 ($h == $hbeg && $mn < $mbeg) ||
3823 ($h == $hbeg && $mn == $mbeg && $s < $sbeg)) {
3824  
3825 # We've gone back past the start of the business day.
3826  
3827 15 my $t2 = $dmb->calc_time_time([$hbeg,$mbeg,$sbeg],[$h,$mn,$s],1);
3828  
3829 15 while (1) {
3830 17 ($y,$m,$d) = @{ $dmb->calc_date_days([$y,$m,$d],-1) };
3831 17 ▶ last if ($self->__is_business_day([$y,$m,$d,$h,$mn,$s]));
Branch: 1 branch
BranchTrueFalseTotal
if $self->__is_business_day([$y, $m, $d, $h, $mn, $s]) 15 2 17
3832 }
3833  
3834 15 ($h,$mn,$s) = @{ $dmb->calc_time_time([$hend,$mend,$send],$t2,1) };
3835 }
3836  
3837 # Now make sure that the date is valid within DST constraints.
3838  
3839 68 ▶ my $force = ( ($dd > 0 || $dh > 0 || $dmn > 0 || $ds > 0) ? 1 : -1 );
Branch: 1 branch
BranchTrueFalseTotal
$dd > 0 || $dh > 0 || $dmn > 0 || $ds > 0 ? : 51 17 68
Condition88%8/9
$dd > 0 or $dh > 0 or $dmn > 0 or $ds > 0
l!l&&r!l&&!r
46517
$dd > 0 or $dh > 0 or $dmn > 0
l!l&&r!l&&!r
46022
$dd > 0 or $dh > 0
l!l&&r!l&&!r
202622
MC/DC75%3/4
$dd > 0 or $dh > 0 or $dmn > 0 or $ds > 0
$dd > 0 $dh > 0 $dmn > 0 $ds > 0
Truth table80%4/5
A or B or C or D
A= $dd > 0B= $dh > 0C= $dmn > 0D= $ds > 0
ABCDresult
1XXX1
01XX1
001X1
00011
00000
3840 68 my($off,$abb);
3841 68 ($date,$off,$isdst,$abb) =
3842 $self->_calc_date_check_dst([$y,$m,$d,$h,$mn,$s],$tz,$isdst,$force);
3843 68 return (0,$date,$off,$isdst,$abb);
3844  
3845 } else {
3846  
3847 # Convert to GTM
3848 # Do the calculation
3849 # Convert back
3850  
3851 1398 my ($dd,$dh,$dm,$ds) = @$delta; # $dd is always 0
3852 1398 my $del = [$dh,$dm,$ds];
3853 1398 my ($err,$offset,$abbrev);
3854  
3855 1398 ($err,$date,$offset,$isdst,$abbrev) =
3856 $dmt->_convert('__calc_date_delta_exact',$date,$tz,'GMT',$isdst);
3857  
3858 1398 $date = $dmb->calc_date_time($date,$del,0);
3859 1398 ▶ return($err,$date,$offset,$isdst,$abbrev)
Branch: 1 branch
BranchTrueFalseTotal
if $date->[0] < 0 or $date->[0] > 9999 1 1397 1398
Condition66%2/3
$date->[0] < 0 or $date->[0] > 9999
l!l&&r!l&&!r
011397
MC/DC50%1/2
$date->[0] < 0 or $date->[0] > 9999
$date->[0] < 0 $date->[0] > 9999
Truth table66%2/3
A or B
A= $date->[0] < 0B= $date->[0] > 9999
ABresult
1X1
011
000
3860 if ($$date[0] < 0 || $$date[0] > 9999);
3861  
3862 1397 ($err,$date,$offset,$isdst,$abbrev) =
3863 $dmt->_convert('__calc_date_delta_exact',$date,'GMT',$tz,$isdst);
3864  
3865 1397 return($err,$date,$offset,$isdst,$abbrev);
3866 }
3867 }
3868  
3869 # This checks to see which time (STD or DST) a date is in. It checks
3870 # $isdst first, and the other value (1-$isdst) second.
3871 #
3872 # If the date is found in either time, it is returned.
3873 #
3874 # If the date is NOT found, then we got here by adding/subtracting 1 day
3875 # from a different value, and we've obtained an invalid value. In this
3876 # case, if $force = 0, then return nothing.
3877 #
3878 # If $force = 1, then go to the previous day and add 24 hours. If force
3879 # is -1, then go to the next day and subtract 24 hours.
3880 #
3881 # Returns:
3882 # ($date,$off,$isdst,$abb)
3883 # or
3884 # (undef)
3885 #
3886 3214 ▶sub _calc_date_check_dst {
Subroutine _calc_date_check_dst: called CC=6 SCAR=30.4
3887 3214 my($self,$date,$tz,$isdst,$force) = @_;
3888 3214 my $dmt = $$self{'tz'};
3889 3214 my $dmb = $$dmt{'base'};
3890 3214 my($abb,$off,$err);
3891  
3892 # Try the date as is in both ISDST and 1-ISDST times
3893  
3894 3214 my $per = $dmt->date_period($date,$tz,1,$isdst);
3895 3214 ▶ if ($per) {
Branch: 1 branch
BranchTrueFalseTotal
if ($per) 3214 0 3214
3896 3214 $abb = $$per[4];
3897 3214 $off = $$per[3];
3898 3214 return($date,$off,$isdst,$abb);
3899 }
3900  
3901 0 $per = $dmt->date_period($date,$tz,1,1-$isdst);
3902 0 ▶ if ($per) {
Branch: 1 branch
BranchTrueFalseTotal
if ($per) 0 0 0
3903 0 $isdst = 1-$isdst;
3904 0 $abb = $$per[4];
3905 0 $off = $$per[3];
3906 0 return($date,$off,$isdst,$abb);
3907 }
3908  
3909 # If we made it here, the date is invalid in this timezone.
3910 # Either return undef, or add/subtract a day from the date
3911 # and find out what time period we're in (all we care about
3912 # is the ISDST value).
3913  
3914 0 ▶ if (! $force) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($force) 0 0 0
3915 0 return(undef);
3916 }
3917  
3918 0 my($dd);
3919 0 ▶ if ($force > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($force > 0) { } 0 0 0
3920 0 $date = $dmb->calc_date_days($date,-1);
3921 0 $dd = 1;
3922 } else {
3923 0 $date = $dmb->calc_date_days($date,+1);
3924 0 $dd = -1;
3925 }
3926  
3927 0 $per = $dmt->date_period($date,$tz,1,$isdst);
3928 0 ▶ $isdst = (1-$isdst) if (! $per);
Branch: 1 branch
BranchTrueFalseTotal
unless $per 0 0 0
3929  
3930 # Now, convert it to GMT, add/subtract 24 hours, and convert
3931 # it back.
3932  
3933 0 ($err,$date,$off,$isdst,$abb) = $dmt->convert_to_gmt($date,$tz,$isdst);
3934 0 $date = $dmb->calc_date_days($date,$dd);
3935 0 ($err,$date,$off,$isdst,$abb) = $dmt->convert_from_gmt($date,$tz);
3936  
3937 0 return($date,$off,$isdst,$abb);
3938 }
3939  
3940 ########################################################################
3941 # MISC METHODS
3942  
3943 8 ▶sub secs_since_1970_GMT {
Subroutine secs_since_1970_GMT: called CC=5 SCAR=16.8
Pod documented
3944 8 my($self,$secs) = @_;
3945  
3946 8 my $dmt = $$self{'tz'};
3947 8 my $dmb = $$dmt{'base'};
3948  
3949 8 ▶ if (defined $secs) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $secs) 3 5 8
3950 3 my $date = $dmb->secs_since_1970($secs);
3951 3 my $err;
3952 3 ($err,$date) = $dmt->convert_from_gmt($date);
3953 3 ▶ return 1 if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 3 3
3954 3 $self->set('date',$date);
3955 3 return 0;
3956 }
3957  
3958 5 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 5 5
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
005
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
3959 0 carp "WARNING: [secs_since_1970_GMT] Object must contain a valid date";
3960 0 return undef;
3961 }
3962  
3963 5 my @date = $self->value('gmt');
3964 5 $secs = $dmb->secs_since_1970(\@date);
3965 5 return $secs;
3966 }
3967  
3968 27 ▶sub week_of_year {
Subroutine week_of_year: called CC=5 SCAR=16.5
Pod documented
3969 27 my($self,$first) = @_;
3970 27 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 27 27
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
0027
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
3971 0 carp "WARNING: [week_of_year] Object must contain a valid date";
3972 0 return undef;
3973 }
3974  
3975 27 my $dmt = $$self{'tz'};
3976 27 my $dmb = $$dmt{'base'};
3977 27 my $date = $$self{'data'}{'date'};
3978 27 my ($y,$m,$d) = @$date;
3979  
3980 27 my $currfirst = $dmb->_config('firstday');
3981 27 $dmb->config('firstday',$first);
3982 27 my($yy,$wk) = $dmb->week_of_year([$y,$m,$d]);
3983 27 $dmb->config('firstday',$currfirst);
3984  
3985 27 ▶ return 53 if ($yy > $y);
Branch: 1 branch
BranchTrueFalseTotal
if $yy > $y 3 24 27
3986 24 ▶ return 0 if ($yy < $y);
Branch: 1 branch
BranchTrueFalseTotal
if $yy < $y 2 22 24
3987 22 return $wk;
3988 }
3989  
3990 7 ▶sub complete {
Subroutine complete: called CC=19 SCAR=34.4
Pod documented
3991 7 my($self,$field) = @_;
3992 7 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 7 7
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
007
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
3993 0 carp "WARNING: [complete] Object must contain a valid date";
3994 0 return undef;
3995 }
3996  
3997 7 ▶ if (! $field) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($field) 4 3 7
3998 return 1 if (! $$self{'data'}{'def'}[1] &&
3999 ! $$self{'data'}{'def'}[2] &&
4000 ! $$self{'data'}{'def'}[3] &&
4001 ! $$self{'data'}{'def'}[4] &&
4002 4 ▶ ! $$self{'data'}{'def'}[5]);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"}{"def"}[1] or $self->{"data"}{"def"}[2] or $self->{"data"}{"def"}[3] or $self->{"data"}{"def"}[4] or $self->{"data"}{"def"}[5] 1 3 4
Condition83%10/12
$self->{"data"}{"def"}[1] or $self->{"data"}{"def"}[2] or $self->{"data"}{"def"}[3] or $self->{"data"}{"def"}[4] or $self->{"data"}{"def"}[5]
l!l&&r!l&&!r
211
$self->{"data"}{"def"}[1] or $self->{"data"}{"def"}[2] or $self->{"data"}{"def"}[3] or $self->{"data"}{"def"}[4]
l!l&&r!l&&!r
202
$self->{"data"}{"def"}[1] or $self->{"data"}{"def"}[2] or $self->{"data"}{"def"}[3]
l!l&&r!l&&!r
112
$self->{"data"}{"def"}[1] or $self->{"data"}{"def"}[2]
l!l&&r!l&&!r
013
MC/DC60%3/5
$self->{"data"}{"def"}[1] or $self->{"data"}{"def"}[2] or $self->{"data"}{"def"}[3] or $self->{"data"}{"def"}[4] or $self->{"data"}{"def"}[5]
$self->{"data"}{"def"}[1] $self->{"data"}{"def"}[2] $self->{"data"}{"def"}[3] $self->{"data"}{"def"}[4] $self->{"data"}{"def"}[5]
Truth table66%4/6
A or B or C or D or E
A= $self->{"data"}{"def"}[1]B= $self->{"data"}{"def"}[2]C= $self->{"data"}{"def"}[3]D= $self->{"data"}{"def"}[4]E= $self->{"data"}{"def"}[5]
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
4003 3 return 0;
4004 }
4005  
4006 3 ▶ if ($field eq 'm') {
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq "m") 1 2 3
4007 1 ▶ return 1 if (! $$self{'data'}{'def'}[1]);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"}{"def"}[1] 1 0 1
4008 }
4009  
4010 2 ▶ if ($field eq 'd') {
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq "d") 0 2 2
4011 0 ▶ return 1 if (! $$self{'data'}{'def'}[2]);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"}{"def"}[2] 0 0 0
4012 }
4013  
4014 2 ▶ if ($field eq 'h') {
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq "h") 1 1 2
4015 1 ▶ return 1 if (! $$self{'data'}{'def'}[3]);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"}{"def"}[3] 1 0 1
4016 }
4017  
4018 1 ▶ if ($field eq 'mn') {
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq "mn") 0 1 1
4019 0 ▶ return 1 if (! $$self{'data'}{'def'}[4]);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"}{"def"}[4] 0 0 0
4020 }
4021  
4022 1 ▶ if ($field eq 's') {
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq "s") 1 0 1
4023 1 ▶ return 1 if (! $$self{'data'}{'def'}[5]);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"}{"def"}[5] 0 1 1
4024 }
4025 1 return 0;
4026 }
4027  
4028 12 ▶sub convert {
Subroutine convert: called CC=5 SCAR=17.7
Pod documented
4029 12 my($self,$zone) = @_;
4030 12 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 12 12
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
0012
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
4031 0 carp "WARNING: [convert] Object must contain a valid date";
4032 0 return 1;
4033 }
4034 12 my $dmt = $$self{'tz'};
4035 12 my $dmb = $$dmt{'base'};
4036  
4037 12 my $zonename = $dmt->_zone($zone);
4038  
4039 12 ▶ if (! $zonename) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($zonename) 0 12 12
4040 0 $$self{'err'} = "[convert] Unable to determine timezone: $zone";
4041 0 return 1;
4042 }
4043  
4044 12 my $date0 = $$self{'data'}{'date'};
4045 12 my $zone0 = $$self{'data'}{'tz'};
4046 12 my $isdst0 = $$self{'data'}{'isdst'};
4047  
4048 12 my($err,$date,$off,$isdst,$abb) = $dmt->convert($date0,$zone0,$zonename,$isdst0);
4049  
4050 12 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 12 12
4051 0 $$self{'err'} = '[convert] Unable to convert date to new timezone';
4052 0 return 1;
4053 }
4054  
4055 12 $self->_init();
4056 12 $$self{'data'}{'date'} = $date;
4057 12 $$self{'data'}{'tz'} = $zonename;
4058 12 $$self{'data'}{'isdst'} = $isdst;
4059 12 $$self{'data'}{'offset'} = $off;
4060 12 $$self{'data'}{'abb'} = $abb;
4061 12 $$self{'data'}{'set'} = 1;
4062  
4063 12 return 0;
4064 }
4065  
4066 ########################################################################
4067 # BUSINESS DAY METHODS
4068  
4069 13 ▶sub is_business_day {
Subroutine is_business_day: called CC=3 SCAR=13.5
Pod documented
4070 13 my($self,$checktime) = @_;
4071 13 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 13 13
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
0013
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
4072 0 carp "WARNING: [is_business_day] Object must contain a valid date";
4073 0 return undef;
4074 }
4075 13 my $date = $$self{'data'}{'date'};
4076 13 return $self->__is_business_day($date,$checktime);
4077 }
4078  
4079 4515 ▶sub __is_business_day {
Subroutine __is_business_day: called CC=12 SCAR=24.9
4080 4515 my($self,$date,$checktime) = @_;
4081 4515 my($y,$m,$d,$h,$mn,$s) = @$date;
4082  
4083 4515 my $dmt = $$self{'tz'};
4084 4515 my $dmb = $$dmt{'base'};
4085  
4086 # Return 0 if it's a weekend.
4087  
4088 4515 my $dow = $dmb->day_of_week([$y,$m,$d]);
4089 4515 ▶ return 0 if ($dow < $dmb->_config('workweekbeg') ||
Branch: 1 branch
BranchTrueFalseTotal
if $dow < $dmb->_config("workweekbeg") or $dow > $dmb->_config("workweekend") 1244 3271 4515
Condition66%2/3
$dow < $dmb->_config("workweekbeg") or $dow > $dmb->_config("workweekend")
l!l&&r!l&&!r
012443271
MC/DC50%1/2
$dow < $dmb->_config("workweekbeg") or $dow > $dmb->_config("workweekend")
$dow < $dmb->_config("workweekbeg") $dow > $dmb->_config("workweekend")
Truth table66%2/3
A or B
A= $dow < $dmb->_config("workweekbeg")B= $dow > $dmb->_config("workweekend")
ABresult
1X1
011
000
4090 $dow > $dmb->_config('workweekend'));
4091  
4092 # Return 0 if it's not during work hours (and we're checking
4093 # for that).
4094  
4095 3271 ▶ if ($checktime &&
Branch: 1 branch
BranchTrueFalseTotal
if ($checktime and not $dmb->_config("workday24hr")) 559 2712 3271
Condition66%2/3
$checktime and not $dmb->_config("workday24hr")
!ll&&!rl&&r
27120559
MC/DC50%1/2
$checktime and not $dmb->_config("workday24hr")
$checktime not $dmb->_config("workday24hr")
Truth table66%2/3
A and not(B)
A= $checktimeB= not $dmb->_config("workday24hr")
ABresult
0X0
100
111
4096 ! $dmb->_config('workday24hr')) {
4097 559 my $t = $dmb->join('hms',[$h,$mn,$s]);
4098 559 my $t0 = $dmb->join('hms',$$dmb{'data'}{'calc'}{'workdaybeg'});
4099 559 my $t1 = $dmb->join('hms',$$dmb{'data'}{'calc'}{'workdayend'});
4100 559 ▶ return 0 if ($t lt $t0 || $t gt $t1);
Branch: 1 branch
BranchTrueFalseTotal
if $t lt $t0 or $t gt $t1 129 430 559
Condition100%3/3
$t lt $t0 or $t gt $t1
l!l&&r!l&&!r
9138430
MC/DC100%2/2
$t lt $t0 or $t gt $t1
$t lt $t0 $t gt $t1
Truth table100%3/3
A or B
A= $t lt $t0B= $t gt $t1
ABresult
1X1
011
000
4101 }
4102  
4103 # Check for holidays
4104  
4105 3142 ▶ if (! $$dmb{'data'}{'init_holidays'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dmb->{"data"}{"init_holidays"}) 1111 2031 3142
4106 1111 $self->_holidays($y-1);
4107 1111 $self->_holidays($y);
4108 1111 $self->_holidays($y+1);
4109 }
4110  
4111 return 0 if (exists $$dmb{'data'}{'holidays'}{'dates'} &&
4112 exists $$dmb{'data'}{'holidays'}{'dates'}{$y+0} &&
4113 exists $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0} &&
4114 3142 ▶ exists $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0}{$d+0});
Branch: 1 branch
BranchTrueFalseTotal
if exists $dmb->{"data"}{"holidays"}{"dates"} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}{$d + 0} 585 2557 3142
Condition100%9/9
exists $dmb->{"data"}{"holidays"}{"dates"} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}{$d + 0}
!ll&&!rl&&r
14831074585
exists $dmb->{"data"}{"holidays"}{"dates"} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}
!ll&&!rl&&r
10274561659
exists $dmb->{"data"}{"holidays"}{"dates"} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}
!ll&&!rl&&r
2947332115
MC/DC100%4/4
exists $dmb->{"data"}{"holidays"}{"dates"} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}{$d + 0}
exists $dmb->{"data"}{"holidays"}{"dates"} exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0} exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0} exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}{$d + 0}
Truth table100%5/5
A and B and C and D
A= exists $dmb->{"data"}{"holidays"}{"dates"}B= exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}C= exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}D= exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}{$d + 0}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
4115  
4116 2557 return 1;
4117 }
4118  
4119 84 ▶sub list_holidays {
Subroutine list_holidays: called CC=6 SCAR=17.9
Pod documented
4120 84 my($self,$y) = @_;
4121 84 my $dmt = $$self{'tz'};
4122 84 my $dmb = $$dmt{'base'};
4123  
4124 84 ▶ $y = $$self{'data'}{'date'}[0] if (! $y && $$self{'data'}{'set'} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if not $y and $self->{"data"}{"set"} == 1 1 83 84
Condition100%3/3
not $y and $self->{"data"}{"set"} == 1
!ll&&!rl&&r
8211
MC/DC100%2/2
not $y and $self->{"data"}{"set"} == 1
not $y $self->{"data"}{"set"} == 1
Truth table100%3/3
not(A) and B
A= not $yB= $self->{"data"}{"set"} == 1
ABresult
0X0
100
111
4125 84 ▶ $y = $dmt->_now('y',1) if (! $y);
Branch: 1 branch
BranchTrueFalseTotal
unless $y 1 83 84
4126 84 $self->_holidays($y-1);
4127 84 $self->_holidays($y);
4128 84 $self->_holidays($y+1);
4129  
4130 84 my @ret;
4131 84 my @m = sort { $a <=> $b } keys %{ $$dmb{'data'}{'holidays'}{'dates'}{$y+0} };
4132 84 foreach my $m (@m) {
4133 130 my @d = sort { $a <=> $b } keys %{ $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m} };
4134 130 foreach my $d (@d) {
4135 163 my $hol = $self->new_date();
4136 163 $hol->set('date',[$y,$m,$d,0,0,0]);
4137 163 push(@ret,$hol);
4138 }
4139 }
4140  
4141 84 return @ret;
4142 }
4143  
4144 33 ▶sub holiday {
Subroutine holiday: called CC=11 SCAR=24.7
Pod documented
4145 33 my($self) = @_;
4146 33 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 33 33
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
0033
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
4147 0 carp "WARNING: [holiday] Object must contain a valid date";
4148 0 return undef;
4149 }
4150 33 my $dmt = $$self{'tz'};
4151 33 my $dmb = $$dmt{'base'};
4152  
4153 33 my($y,$m,$d) = @{ $$self{'data'}{'date'} };
4154 33 $self->_holidays($y-1);
4155 33 $self->_holidays($y);
4156 33 $self->_holidays($y+1);
4157  
4158 33 ▶ if (exists $$dmb{'data'}{'holidays'}{'dates'}{$y+0} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}{$d + 0}) 23 10 33
Condition83%5/6
exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}{$d + 0}
!ll&&!rl&&r
6423
exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}
!ll&&!rl&&r
0627
MC/DC66%2/3
exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0} and exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}{$d + 0}
exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0} exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0} exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}{$d + 0}
Truth table75%3/4
A and B and C
A= exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}B= exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}C= exists $dmb->{"data"}{"holidays"}{"dates"}{$y + 0}{$m + 0}{$d + 0}
ABCresult
0XX0
10X0
1100
1111
4159 exists $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0} &&
4160 exists $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0}{$d+0}) {
4161 23 my @tmp = @{ $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0}{$d+0} };
4162  
4163 23 foreach my $tmp (@tmp) {
4164 28 ▶ $tmp = '' if ($tmp =~ /DMunnamed/);
Branch: 1 branch
BranchTrueFalseTotal
if $tmp =~ /DMunnamed/ 2 26 28
4165 }
4166  
4167 23 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 22 1 23
4168 22 ▶ return () if (! @tmp);
Branch: 1 branch
BranchTrueFalseTotal
unless @tmp 0 22 22
4169 22 return @tmp;
4170 } else {
4171 1 ▶ return '' if (! @tmp);
Branch: 1 branch
BranchTrueFalseTotal
unless @tmp 0 1 1
4172 1 return $tmp[0];
4173 }
4174 }
4175 10 return undef;
4176 }
4177  
4178 12 ▶sub next_business_day {
Subroutine next_business_day: called CC=3 SCAR=12.6
Pod documented
4179 12 my($self,$off,$checktime) = @_;
4180 12 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 12 12
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
0012
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
4181 0 carp "WARNING: [next_business_day] Object must contain a valid date";
4182 0 return undef;
4183 }
4184 12 my $date = $$self{'data'}{'date'};
4185  
4186 12 $date = $self->__nextprev_business_day(0,$off,$checktime,$date);
4187 12 $self->set('date',$date);
4188 12 return;
4189 }
4190  
4191 12 ▶sub prev_business_day {
Subroutine prev_business_day: called CC=3 SCAR=12.6
Pod documented
4192 12 my($self,$off,$checktime) = @_;
4193 12 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 12 12
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
0012
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
4194 0 carp "WARNING: [prev_business_day] Object must contain a valid date";
4195 0 return undef;
4196 }
4197 12 my $date = $$self{'data'}{'date'};
4198  
4199 12 $date = $self->__nextprev_business_day(1,$off,$checktime,$date);
4200 12 $self->set('date',$date);
4201 12 return;
4202 }
4203  
4204 530 ▶sub __nextprev_business_day {
Subroutine __nextprev_business_day: called CC=6 SCAR=17.9
4205 530 my($self,$prev,$off,$checktime,$date) = @_;
4206 530 my($y,$m,$d,$h,$mn,$s) = @$date;
4207  
4208 530 my $dmt = $$self{'tz'};
4209 530 my $dmb = $$dmt{'base'};
4210  
4211 # Get day 0
4212  
4213 530 ▶ while (! $self->__is_business_day([$y,$m,$d,$h,$mn,$s],$checktime)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->__is_business_day([$y, $m, $d, $h, $mn, $s], $checktime)) 455 530 985
4214 455 ▶ if ($checktime) {
Branch: 1 branch
BranchTrueFalseTotal
if ($checktime) { } 244 211 455
4215 ($y,$m,$d,$h,$mn,$s) =
4216 244 @{ $self->__next_prev([$y,$m,$d,$h,$mn,$s],1,undef,0,
4217 244 $$dmb{'data'}{'calc'}{'workdaybeg'}) };
4218 } else {
4219 # Move forward 1 day
4220 211 ($y,$m,$d) = @{ $dmb->calc_date_days([$y,$m,$d],1) };
4221 }
4222 }
4223  
4224 # Move $off days into the future/past
4225  
4226 530 ▶ while ($off > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($off > 0) 140 530 670
4227 140 while (1) {
4228 221 ▶ if ($prev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev) { } 92 129 221
4229 # Move backward 1 day
4230 92 ($y,$m,$d) = @{ $dmb->calc_date_days([$y,$m,$d],-1) };
4231 } else {
4232 # Move forward 1 day
4233 129 ($y,$m,$d) = @{ $dmb->calc_date_days([$y,$m,$d],1) };
4234 }
4235 221 ▶ last if ($self->__is_business_day([$y,$m,$d,$h,$mn,$s]));
Branch: 1 branch
BranchTrueFalseTotal
if $self->__is_business_day([$y, $m, $d, $h, $mn, $s]) 140 81 221
4236 }
4237 140 $off--;
4238 }
4239  
4240 530 return [$y,$m,$d,$h,$mn,$s];
4241 }
4242  
4243 6 ▶sub nearest_business_day {
Subroutine nearest_business_day: called CC=4 SCAR=15.0
Pod documented
4244 6 my($self,$tomorrow) = @_;
4245 6 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 6 6
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
006
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
4246 0 carp "WARNING: [nearest_business_day] Object must contain a valid date";
4247 0 return undef;
4248 }
4249  
4250 6 my $date = $$self{'data'}{'date'};
4251 6 $date = $self->__nearest_business_day($tomorrow,$date);
4252  
4253 # If @date is empty, the date is a business day and doesn't need
4254 # to be changed.
4255  
4256 6 ▶ return if (! defined($date));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $date 4 2 6
4257  
4258 2 $self->set('date',$date);
4259 2 return;
4260 }
4261  
4262 6 ▶sub __nearest_business_day {
Subroutine __nearest_business_day: called CC=6 SCAR=18.0
4263 6 my($self,$tomorrow,$date) = @_;
4264  
4265 # We're done if this is a business day
4266 6 ▶ return undef if ($self->__is_business_day($date,0));
Branch: 1 branch
BranchTrueFalseTotal
if $self->__is_business_day($date, 0) 4 2 6
4267  
4268 2 my $dmt = $$self{'tz'};
4269 2 my $dmb = $$dmt{'base'};
4270  
4271 2 ▶ $tomorrow = $dmb->_config('tomorrowfirst') if (! defined $tomorrow);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tomorrow 2 0 2
4272  
4273 2 my($a1,$a2);
4274 2 ▶ if ($tomorrow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tomorrow) { } 2 0 2
4275 2 ($a1,$a2) = (1,-1);
4276 } else {
4277 0 ($a1,$a2) = (-1,1);
4278 }
4279  
4280 2 my ($y,$m,$d,$h,$mn,$s) = @$date;
4281 2 my ($y1,$m1,$d1) = ($y,$m,$d);
4282 2 my ($y2,$m2,$d2) = ($y,$m,$d);
4283  
4284 2 while (1) {
4285 2 ($y1,$m1,$d1) = @{ $dmb->calc_date_days([$y1,$m1,$d1],$a1) };
4286 2 ▶ if ($self->__is_business_day([$y1,$m1,$d1,$h,$mn,$s],0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__is_business_day([$y1, $m1, $d1, $h, $mn, $s], 0)) 1 1 2
4287 1 ($y,$m,$d) = ($y1,$m1,$d1);
4288 1 last;
4289 }
4290 1 ($y2,$m2,$d2) = @{ $dmb->calc_date_days([$y2,$m2,$d2],$a2) };
4291 1 ▶ if ($self->__is_business_day([$y2,$m2,$d2,$h,$mn,$s],0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__is_business_day([$y2, $m2, $d2, $h, $mn, $s], 0)) 1 0 1
4292 1 ($y,$m,$d) = ($y2,$m2,$d2);
4293 1 last;
4294 }
4295 }
4296  
4297 2 return [$y,$m,$d,$h,$mn,$s];
4298 }
4299  
4300 # We need to create all the objects which will be used to determine holidays.
4301 # By doing this once only, a lot of time is saved.
4302 #
4303 34 ▶sub _holiday_objs {
Subroutine _holiday_objs: called CC=8 SCAR=21.1
4304 34 my($self) = @_;
4305 34 my $dmt = $$self{'tz'};
4306 34 my $dmb = $$dmt{'base'};
4307  
4308 34 $$dmb{'data'}{'holidays'}{'init'} = 1;
4309  
4310 # Go through all of the strings from the config file.
4311 #
4312 34 my (@str) = @{ $$dmb{'data'}{'sections'}{'holidays'} };
4313 34 $$dmb{'data'}{'holidays'}{'defs'} = [];
4314  
4315 # Keep track of the holiday names
4316 34 my $unnamed = 0;
4317  
4318 LINE:
4319 34 ▶ while (@str) {
Branch: 1 branch
BranchTrueFalseTotal
if (@str) 207 34 241
4320 207 my($string) = shift(@str);
4321 207 my($name) = shift(@str);
4322 207 ▶ if (! $name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 14 193 207
4323 14 $unnamed++;
4324 14 $name = "DMunnamed $unnamed";
4325 }
4326  
4327 # If $string is a parse_date string AND it contains a year, we'll
4328 # store the date as a holiday, but not store the holiday description
4329 # so it never needs to be re-parsed.
4330  
4331 207 my $date = $self->new_date();
4332 207 my $err = $date->parse_date($string);
4333  
4334 207 ▶ if (! $err) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 105 102 207
4335 105 my($y,$m,$d) = @{ $$date{'data'}{'date'} };
4336  
4337 105 ▶ if ($$date{'data'}{'def'}[0] eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($date->{'data'}{'def'}[0] eq '') { } 92 13 105
4338 # Lines of the form: Jun 12
4339 #
4340 # We will NOT cache this holiday because we want to only
4341 # cache holidays from lines like 'Jun 12 1972' during this
4342 # phase so we find conflicts.
4343  
4344 92 push(@{ $$dmb{'data'}{'holidays'}{'defs'} },$name,$string);
4345  
4346 } else {
4347 # Lines of the form: Jun 12 1972
4348 #
4349 # We'll cache these to make sure we don't have two lines:
4350 # Jun 12 1972 = Some Holiday
4351 # Jun 13 1972 = Some Holiday
4352  
4353 13 ▶ if (exists $$dmb{'data'}{'holidays'}{'hols'}{$name}{$y+0}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dmb->{"data"}{"holidays"}{"hols"}{$name}{$y + 0}) 0 13 13
4354 0 carp "WARNING: Holiday defined twice for one year: $name [$y]";
4355 0 next LINE;
4356 }
4357  
4358 13 $$dmb{'data'}{'holidays'}{'yhols'}{$y+0}{$name} = [$y,$m,$d];
4359 13 $$dmb{'data'}{'holidays'}{'hols'}{$name}{$y+0} = [$y,$m,$d];
4360  
4361 13 ▶ if (exists $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0}{$d+0}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dmb->{'data'}{'holidays'}{'dates'}{$y + 0}{$m + 0}{$d + 0}) { } 0 13 13
4362 0 push @{ $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0}{$d+0} },$name;
4363 } else {
4364 13 $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0}{$d+0} = [ $name ];
4365 }
4366 }
4367 105 next LINE;
4368 }
4369 102 $date->err(1);
4370  
4371 # If $string is a recurrence, we'll create a Recur object (which we
4372 # only have to do once) and store it.
4373  
4374 102 my $recur = $self->new_recur();
4375 102 $err = $recur->parse($string);
4376 102 ▶ if (! $err) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 102 0 102
4377 102 push(@{ $$dmb{'data'}{'holidays'}{'defs'} },$name,$recur);
4378 102 next LINE;
4379 }
4380 0 $recur->err(1);
4381  
4382 0 carp "WARNING: invalid holiday description: $string";
4383 }
4384 34 return;
4385 }
4386  
4387 # Make sure that holidays are done for a given year.
4388 #
4389 3711 ▶sub _holidays {
Subroutine _holidays: called CC=11 SCAR=24.0
4390 3711 my($self,$year) = @_;
4391  
4392 3711 my $dmt = $$self{'tz'};
4393 3711 my $dmb = $$dmt{'base'};
4394  
4395 3711 ▶ return if ($$dmb{'data'}{'holidays'}{'ydone'}{$year+0});
Branch: 1 branch
BranchTrueFalseTotal
if $dmb->{"data"}{"holidays"}{"ydone"}{$year + 0} 3446 265 3711
4396 265 ▶ $self->_holiday_objs() if (! $$dmb{'data'}{'holidays'}{'init'});
Branch: 1 branch
BranchTrueFalseTotal
unless $dmb->{"data"}{"holidays"}{"init"} 34 231 265
4397  
4398 # Parse the year
4399  
4400 # Get the objects and set them to use the new year. Also, get the
4401 # range for recurrences.
4402  
4403 265 my @hol = @{ $$dmb{'data'}{'holidays'}{'defs'} };
4404  
4405 265 my $beg = "$year-01-01-00:00:00";
4406 265 my $end = "$year-12-31-23:59:59";
4407  
4408 # Get the date for each holiday.
4409  
4410 265 $$dmb{'data'}{'init_holidays'} = 1;
4411 265 $$dmb{'data'}{'tmpnow'} = [$year,1,1,0,0,0];
4412  
4413 HOLIDAY:
4414 265 ▶ while (@hol) {
Branch: 1 branch
BranchTrueFalseTotal
if (@hol) 1374 265 1639
4415  
4416 1374 my $name = shift(@hol);
4417 1374 my $obj = shift(@hol);
4418  
4419 # Each holiday only gets defined once per year
4420 1374 ▶ next if (exists $$dmb{'data'}{'holidays'}{'hols'}{$name}{$year+0});
Branch: 1 branch
BranchTrueFalseTotal
if exists $dmb->{"data"}{"holidays"}{"hols"}{$name}{$year + 0} 24 1350 1374
4421  
4422 1350 ▶ if (ref($obj)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj) { } 766 584 1350
4423 # It's a recurrence
4424  
4425 # We have to initialize the recurrence as it may contain idates
4426 # and dates outside of this range that are not correct.
4427  
4428 766 $obj->_init_dates();
4429  
4430 # If the recurrence has a date range built in, we won't override it.
4431 # Otherwise, we'll only look for dates in this year.
4432  
4433 766 my @dates;
4434 766 ▶ if ($obj->start() && $obj->end()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->start and $obj->end) { } 84 682 766
Condition66%2/3
$obj->start and $obj->end
!ll&&!rl&&r
682084
MC/DC50%1/2
$obj->start and $obj->end
$obj->start $obj->end
Truth table66%2/3
A and B
A= $obj->startB= $obj->end
ABresult
0X0
100
111
4435 84 @dates = $obj->dates();
4436 } else {
4437 682 @dates = $obj->dates($beg,$end,1);
4438 }
4439  
4440 766 foreach my $date (@dates) {
4441 878 my($y,$m,$d) = @{ $$date{'data'}{'date'} };
4442  
4443 878 $$dmb{'data'}{'holidays'}{'yhols'}{$year+0}{$name} = [$y,$m,$d];
4444 878 $$dmb{'data'}{'holidays'}{'hols'}{$name}{$year+0} = [$y,$m,$d];
4445  
4446 878 ▶ if (exists $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0}{$d+0}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dmb->{'data'}{'holidays'}{'dates'}{$y + 0}{$m + 0}{$d + 0}) { } 213 665 878
4447 213 push @{ $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0}{$d+0} },$name;
4448 } else {
4449 665 $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0}{$d+0} = [$name];
4450 }
4451 }
4452  
4453 } else {
4454 584 my $date = $self->new_date();
4455 584 $date->parse_date($obj);
4456 584 my($y,$m,$d) = @{ $$date{'data'}{'date'} };
4457  
4458 584 $$dmb{'data'}{'holidays'}{'yhols'}{$year+0}{$name} = [$y,$m,$d];
4459 584 $$dmb{'data'}{'holidays'}{'hols'}{$name}{$year+0} = [$y,$m,$d];
4460  
4461 584 ▶ if (exists $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0}{$d+0}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dmb->{'data'}{'holidays'}{'dates'}{$y + 0}{$m + 0}{$d + 0}) { } 8 576 584
4462 8 push @{ $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0}{$d+0} },$name;
4463 } else {
4464 576 $$dmb{'data'}{'holidays'}{'dates'}{$y+0}{$m+0}{$d+0} = [$name];
4465 }
4466 }
4467 }
4468  
4469 265 $$dmb{'data'}{'init_holidays'} = 0;
4470 265 $$dmb{'data'}{'tmpnow'} = [];
4471 265 $$dmb{'data'}{'holidays'}{'ydone'}{$year+0} = 1;
4472 265 return;
4473 }
4474  
4475 ########################################################################
4476 # PRINTF METHOD
4477  
4478 170 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
4479 170 my %pad_0 = map { $_,1 } qw ( Y m d H M S I j G W L U );
4480 170 my %pad_0_pos = map { $_,1 } qw ( Y m d H M S I j G W L U V g );
4481  
4482 170 my %pad_sp = map { $_,1 } qw ( y f e k i );
4483 170 my %pad_sp_pos = map { $_,1 } qw ( y f e k i l );
4484  
4485 170 my %hr = map { $_,1 } qw ( H k I i );
4486 170 my %hr_pos = map { $_,1 } qw ( H k I i l );
4487  
4488 170 my %dow = map { $_,1 } qw ( v a A w );
4489 170 my %dow_pos = map { $_,1 } qw ( v a A w u );
4490  
4491 170 my %num = map { $_,1 } qw ( Y m d H M S y f e k I i j G W L U );
4492 170 my %num_pos = map { $_,1 } qw ( Y m d H M S y f e k I i j G W L U g V C l u );
4493  
4494 61 ▶ sub printf {
Subroutine printf: called CC=130 SCAR=48.9
Pod documented
4495 61 my($self,@in) = @_;
4496 61 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 61 61
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
0061
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
4497 0 carp "WARNING: [printf] Object must contain a valid date";
4498 0 return undef;
4499 }
4500  
4501 61 my $dmt = $$self{'tz'};
4502 61 my $dmb = $$dmt{'base'};
4503  
4504 61 my $posix = $dmb->_config('use_posix_printf');
4505  
4506 61 my($y,$m,$d,$h,$mn,$s) = @{ $$self{'data'}{'date'} };
4507  
4508 61 my(@out);
4509 61 foreach my $in (@in) {
4510 63 my $out = '';
4511 63 ▶ while ($in) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in) 698 63 761
4512 698 ▶ last if ($in eq '%');
Branch: 1 branch
BranchTrueFalseTotal
if $in eq "%" 0 698 698
4513  
4514 # Everything up to the first '%'
4515  
4516 698 ▶ if ($in =~ s/^([^%]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in =~ s/^([^%]+)//) 288 410 698
4517 288 $out .= $1;
4518 288 next;
4519 }
4520  
4521 # Extended formats: %<...>
4522  
4523 410 ▶ if ($in =~ s/^%<([^>]+)>//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in =~ s/^%<([^>]+)>//) 20 390 410
4524 20 my $f = $1;
4525 20 my $val;
4526  
4527 20 ▶ if ($f =~ /^a=([1-7])$/) {
Branch: 7 branches
BranchTrueFalseTotal
if ($f =~ /^a=([1-7])$/) { } 3 17 20
elsif ($f =~ /^v=([1-7])$/) { } 3 14 17
elsif ($f =~ /^A=([1-7])$/) { } 3 11 14
elsif ($f =~ /^p=([1-2])$/) { } 2 9 11
elsif ($f =~ /^b=(0?[1-9]|1[0-2])$/) { } 3 6 9
elsif ($f =~ /^B=(0?[1-9]|1[0-2])$/) { } 3 3 6
elsif ($f =~ /^E=(0?[1-9]|[1-4][0-9]|5[0-3])$/) { } 3 0 3
4528 3 $val = $$dmb{'data'}{'wordlist'}{'day_abb'}[$1-1];
4529  
4530 } elsif ($f =~ /^v=([1-7])$/) {
4531 3 $val = $$dmb{'data'}{'wordlist'}{'day_char'}[$1-1];
4532  
4533 } elsif ($f =~ /^A=([1-7])$/) {
4534 3 $val = $$dmb{'data'}{'wordlist'}{'day_name'}[$1-1];
4535  
4536 } elsif ($f =~ /^p=([1-2])$/) {
4537 2 $val = $$dmb{'data'}{'wordlist'}{'ampm'}[$1-1];
4538  
4539 } elsif ($f =~ /^b=(0?[1-9]|1[0-2])$/) {
4540 3 $val = $$dmb{'data'}{'wordlist'}{'month_abb'}[$1-1];
4541  
4542 } elsif ($f =~ /^B=(0?[1-9]|1[0-2])$/) {
4543 3 $val = $$dmb{'data'}{'wordlist'}{'month_name'}[$1-1];
4544  
4545 } elsif ($f =~ /^E=(0?[1-9]|[1-4][0-9]|5[0-3])$/) {
4546 3 $val = $$dmb{'data'}{'wordlist'}{'nth'}[$1-1];
4547  
4548 } else {
4549 0 $val = '%<' . $1 . '>';
4550 }
4551 20 $out .= $val;
4552 20 next;
4553 }
4554  
4555 # Normals one-character formats
4556  
4557 390 $in =~ s/^%(.)//s;
4558 390 my $f = $1;
4559  
4560 390 ▶ if (exists $$self{'data'}{'f'}{$f}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"data"}{"f"}{$f}) 43 347 390
4561 43 $out .= $$self{'data'}{'f'}{$f};
4562 43 next;
4563 }
4564  
4565 347 my ($val,$pad,$len,$dow);
4566  
4567 347 ▶ if ((! $posix && exists $pad_0{$f}) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not $posix and exists $pad_0{$f} or $posix and exists $pad_0_pos{$f}) 176 171 347
Condition100%9/9
not $posix and exists $pad_0{$f} or $posix and exists $pad_0_pos{$f}
l!l&&r!l&&!r
14927171
not $posix and exists $pad_0{$f}
!ll&&!rl&&r
41157149
$posix and exists $pad_0_pos{$f}
!ll&&!rl&&r
1571427
MC/DC75%3/4
not $posix and exists $pad_0{$f} or $posix and exists $pad_0_pos{$f}
not $posix exists $pad_0{$f} $posix exists $pad_0_pos{$f}
Truth table57%4/7
not(A) and B or C and D
A= not $posixB= exists $pad_0{$f}C= $posixD= exists $pad_0_pos{$f}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
4568 ($posix && exists $pad_0_pos{$f})) {
4569 176 $pad = '0';
4570 }
4571  
4572 347 ▶ if ((! $posix && exists $pad_sp{$f}) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not $posix and exists $pad_sp{$f} or $posix and exists $pad_sp_pos{$f}) 24 323 347
Condition100%9/9
not $posix and exists $pad_sp{$f} or $posix and exists $pad_sp_pos{$f}
l!l&&r!l&&!r
231323
not $posix and exists $pad_sp{$f}
!ll&&!rl&&r
4128323
$posix and exists $pad_sp_pos{$f}
!ll&&!rl&&r
283401
MC/DC75%3/4
not $posix and exists $pad_sp{$f} or $posix and exists $pad_sp_pos{$f}
not $posix exists $pad_sp{$f} $posix exists $pad_sp_pos{$f}
Truth table57%4/7
not(A) and B or C and D
A= not $posixB= exists $pad_sp{$f}C= $posixD= exists $pad_sp_pos{$f}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
4573 ($posix && exists $pad_sp_pos{$f})) {
4574 24 $pad = ' ';
4575 }
4576  
4577 # Year/week
4578  
4579 347 ▶ if ($f eq 'G' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq "G" or $f eq "W" or $f eq "L" or $f eq "U" or $f eq "g" and $posix or $f eq "V" and $posix) 48 299 347
Condition100%21/21
$f eq "G" or $f eq "W" or $f eq "L" or $f eq "U" or $f eq "g" and $posix or $f eq "V" and $posix
l!l&&r!l&&!r
444299
$f eq "G" or $f eq "W" or $f eq "L" or $f eq "U" or $f eq "g" and $posix
l!l&&r!l&&!r
404303
$f eq "G" or $f eq "W" or $f eq "L" or $f eq "U"
l!l&&r!l&&!r
3010307
$f eq "G" or $f eq "W" or $f eq "L"
l!l&&r!l&&!r
219317
$f eq "G" or $f eq "W"
l!l&&r!l&&!r
1011326
$f eq "g" and $posix
!ll&&!rl&&r
290134
$f eq "V" and $posix
!ll&&!rl&&r
29814
MC/DC100%8/8
$f eq "G" or $f eq "W" or $f eq "L" or $f eq "U" or $f eq "g" and $posix or $f eq "V" and $posix
$f eq "G" $f eq "W" $f eq "L" $f eq "U" $f eq "g" $posix $f eq "V" $posix
Truth table81%9/11
A or B or C or D or E and F or G and H
A= $f eq "G"B= $f eq "W"C= $f eq "L"D= $f eq "U"E= $f eq "g"F= $posixG= $f eq "V"H= $posix
ABCDEFGHresult
1XXXXXXX1
01XXXXXX1
001XXXXX1
0001XXXX1
000011XX1
00000X111
000010111
00000X0X0
00000X100
0000100X0
000010100
4580 $f eq 'W' ||
4581 $f eq 'L' ||
4582 $f eq 'U' ||
4583 ($f eq 'g' && $posix) ||
4584 ($f eq 'V' && $posix)
4585 ) {
4586  
4587 48 my $week1ofyear;
4588 my $firstday;
4589 48 ▶ if ($f eq 'L' || $f eq 'U') {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq 'L' or $f eq 'U') { } 19 29 48
Condition100%3/3
$f eq "L" or $f eq "U"
l!l&&r!l&&!r
91029
MC/DC100%2/2
$f eq "L" or $f eq "U"
$f eq "L" $f eq "U"
Truth table100%3/3
A or B
A= $f eq "L"B= $f eq "U"
ABresult
1X1
011
000
4590 19 $firstday = 7;
4591 } else {
4592 29 $firstday = 1;
4593 }
4594  
4595 48 ▶ if ($posix && ($f eq 'G' ||
Branch: 3 branches
BranchTrueFalseTotal
if ($posix and $f eq 'G' || $f eq 'g' || $f eq 'V' || $f eq 'L') { } 16 32 48
elsif ($posix and $f eq 'W') { } 4 28 32
elsif ($posix and $f eq 'U') { } 4 24 28
Condition100%12/12
$posix and $f eq "G" || $f eq "g" || $f eq "V" || $f eq "L"
!ll&&!rl&&r
24816
$f eq "G" or $f eq "g" or $f eq "V" or $f eq "L"
l!l&&r!l&&!r
1248
$f eq "G" or $f eq "g" or $f eq "V"
l!l&&r!l&&!r
8412
$f eq "G" or $f eq "g"
l!l&&r!l&&!r
4416
MC/DC100%5/5
$posix and $f eq "G" || $f eq "g" || $f eq "V" || $f eq "L"
$posix $f eq "G" $f eq "g" $f eq "V" $f eq "L"
Truth table100%6/6
A and B or C or D or E
A= $posixB= $f eq "G"C= $f eq "g"D= $f eq "V"E= $f eq "L"
ABCDEresult
0XXXX0
100000
11XXX1
101XX1
1001X1
100011
4596 $f eq 'g' ||
4597 $f eq 'V' ||
4598 $f eq 'L')) {
4599 16 $week1ofyear = 'jan4';
4600 ▶ } elsif ($posix && ($f eq 'W')) {
Condition100%3/3
$posix and $f eq "W"
!ll&&!rl&&r
2444
MC/DC100%2/2
$posix and $f eq "W"
$posix $f eq "W"
Truth table100%3/3
A and B
A= $posixB= $f eq "W"
ABresult
0X0
100
111
4601 4 $week1ofyear = 1;
4602 ▶ } elsif ($posix && ($f eq 'U')) {
Condition66%2/3
$posix and $f eq "U"
!ll&&!rl&&r
2404
MC/DC50%1/2
$posix and $f eq "U"
$posix $f eq "U"
Truth table66%2/3
A and B
A= $posixB= $f eq "U"
ABresult
0X0
100
111
4603 4 $week1ofyear = 7;
4604 } else {
4605 24 $week1ofyear = $dmb->_config('week1ofyear');
4606 }
4607  
4608 48 my($yy,$ww) = $dmb->_week_of_year($firstday,$week1ofyear,[$y,$m,$d]);
4609 48 ▶ if ($f eq 'G' ||
Branch: 2 branches
BranchTrueFalseTotal
if ($f eq 'G' or $f eq 'L') { } 19 29 48
elsif ($f eq 'g') { } 4 25 29
Condition100%3/3
$f eq "G" or $f eq "L"
l!l&&r!l&&!r
10929
MC/DC100%2/2
$f eq "G" or $f eq "L"
$f eq "G" $f eq "L"
Truth table100%3/3
A or B
A= $f eq "G"B= $f eq "L"
ABresult
1X1
011
000
4610 $f eq 'L') {
4611 19 $val = $yy;
4612 19 $len = 4;
4613  
4614 } elsif ($f eq 'g') {
4615 4 $yy =~ /^..(..)/;
4616 4 $val = $1;
4617 4 $len = 2;
4618  
4619 } else {
4620 25 $val = $ww;
4621 25 $len = 2;
4622 }
4623 }
4624  
4625 347 ▶ if ($f eq 'Y' || $f eq 'y') {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq "Y" or $f eq "y") 29 318 347
Condition100%3/3
$f eq "Y" or $f eq "y"
l!l&&r!l&&!r
245318
MC/DC100%2/2
$f eq "Y" or $f eq "y"
$f eq "Y" $f eq "y"
Truth table100%3/3
A or B
A= $f eq "Y"B= $f eq "y"
ABresult
1X1
011
000
4626 29 $val = $y;
4627 29 $len = 4;
4628 }
4629  
4630 347 ▶ if ($f eq 'C' && $posix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq "C" and $posix) 1 346 347
Condition100%3/3
$f eq "C" and $posix
!ll&&!rl&&r
34511
MC/DC100%2/2
$f eq "C" and $posix
$f eq "C" $posix
Truth table100%3/3
A and B
A= $f eq "C"B= $posix
ABresult
0X0
100
111
4631 1 $y =~ /^(..)/;
4632 1 $val = $1;
4633 1 $len = 2;
4634 }
4635  
4636 347 ▶ if ($f eq 'm' || $f eq 'f') {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq "m" or $f eq "f") 9 338 347
Condition100%3/3
$f eq "m" or $f eq "f"
l!l&&r!l&&!r
72338
MC/DC100%2/2
$f eq "m" or $f eq "f"
$f eq "m" $f eq "f"
Truth table100%3/3
A or B
A= $f eq "m"B= $f eq "f"
ABresult
1X1
011
000
4637 9 $val = $m;
4638 9 $len = 2;
4639 }
4640  
4641 347 ▶ if ($f eq 'd' || $f eq 'e') {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq "d" or $f eq "e") 30 317 347
Condition100%3/3
$f eq "d" or $f eq "e"
l!l&&r!l&&!r
2010317
MC/DC100%2/2
$f eq "d" or $f eq "e"
$f eq "d" $f eq "e"
Truth table100%3/3
A or B
A= $f eq "d"B= $f eq "e"
ABresult
1X1
011
000
4642 30 $val = $d;
4643 30 $len = 2;
4644 }
4645  
4646 347 ▶ if ($f eq 'j') {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq "j") 3 344 347
4647 3 $val = $dmb->day_of_year([$y,$m,$d]);
4648 3 $len = 3;
4649 }
4650  
4651  
4652 347 ▶ if ((! $posix && exists $hr{$f}) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not $posix and exists $hr{$f} or $posix and exists $hr_pos{$f}) 35 312 347
Condition100%9/9
not $posix and exists $hr{$f} or $posix and exists $hr_pos{$f}
l!l&&r!l&&!r
341312
not $posix and exists $hr{$f}
!ll&&!rl&&r
4127234
$posix and exists $hr_pos{$f}
!ll&&!rl&&r
272401
MC/DC75%3/4
not $posix and exists $hr{$f} or $posix and exists $hr_pos{$f}
not $posix exists $hr{$f} $posix exists $hr_pos{$f}
Truth table57%4/7
not(A) and B or C and D
A= not $posixB= exists $hr{$f}C= $posixD= exists $hr_pos{$f}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
4653 ( $posix && exists $hr_pos{$f})) {
4654 35 $val = $h;
4655 35 ▶ if ($f eq 'I' || $f eq 'i' || $f eq 'l') {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq "I" or $f eq "i" or $f eq "l") 8 27 35
Condition100%6/6
$f eq "I" or $f eq "i" or $f eq "l"
l!l&&r!l&&!r
7127
$f eq "I" or $f eq "i"
l!l&&r!l&&!r
4328
MC/DC100%3/3
$f eq "I" or $f eq "i" or $f eq "l"
$f eq "I" $f eq "i" $f eq "l"
Truth table100%4/4
A or B or C
A= $f eq "I"B= $f eq "i"C= $f eq "l"
ABCresult
1XX1
01X1
0011
0000
4656 8 ▶ $val -= 12 if ($val > 12);
Branch: 1 branch
BranchTrueFalseTotal
if $val > 12 2 6 8
4657 8 ▶ $val = 12 if ($val == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $val == 0 0 8 8
4658 }
4659 35 $len = 2;
4660 }
4661  
4662 347 ▶ if ($f eq 'M') {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq "M") 24 323 347
4663 24 $val = $mn;
4664 24 $len = 2;
4665 }
4666  
4667 347 ▶ if ($f eq 'S') {
Branch: 1 branch
BranchTrueFalseTotal
if ($f eq "S") 22 325 347
4668 22 $val = $s;
4669 22 $len = 2;
4670 }
4671  
4672 347 ▶ if ((! $posix && exists $dow{$f}) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not $posix and exists $dow{$f} or $posix and exists $dow_pos{$f}) 36 311 347
Condition100%9/9
not $posix and exists $dow{$f} or $posix and exists $dow_pos{$f}
l!l&&r!l&&!r
306311
not $posix and exists $dow{$f}
!ll&&!rl&&r
4127630
$posix and exists $dow_pos{$f}
!ll&&!rl&&r
276356
MC/DC75%3/4
not $posix and exists $dow{$f} or $posix and exists $dow_pos{$f}
not $posix exists $dow{$f} $posix exists $dow_pos{$f}
Truth table57%4/7
not(A) and B or C and D
A= not $posixB= exists $dow{$f}C= $posixD= exists $dow_pos{$f}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
4673 ($posix && exists $dow_pos{$f})) {
4674 36 $dow = $dmb->day_of_week([$y,$m,$d]);
4675 36 ▶ $dow = 7 if ($f eq 'u' && $dow == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $f eq "u" and $dow == 0 0 36 36
Condition66%2/3
$f eq "u" and $dow == 0
!ll&&!rl&&r
3420
MC/DC0%0/2
$f eq "u" and $dow == 0
$f eq "u" $dow == 0
Truth table66%2/3
A and B
A= $f eq "u"B= $dow == 0
ABresult
0X0
100
111
4676 36 $val = $dow;
4677 36 $len = 1;
4678 }
4679  
4680 ###
4681  
4682 347 ▶ if ( (! $posix && exists $num{$f}) ||
Branch: 33 branches
BranchTrueFalseTotal
if (not $posix and exists $num{$f} or $posix and exists $num_pos{$f}) { } 203 144 347
elsif ($f eq 'b' or $f eq 'h') { } 24 120 144
elsif ($f eq 'B') { } 3 117 120
elsif ($f eq 'v') { } 2 115 117
elsif ($f eq 'a') { } 18 97 115
elsif ($f eq 'A') { } 3 94 97
elsif ($f eq 'w') { } 11 83 94
elsif ($f eq 'p' or $f eq 'P' and $posix) { } 5 78 83
elsif ($f eq 'Z') { } 19 59 78
elsif ($f eq 'N') { } 4 55 59
elsif ($f eq 'z') { } 4 51 55
elsif ($f eq 'E') { } 2 49 51
elsif ($f eq 's') { } 2 47 49
elsif ($f eq 'o') { } 2 45 47
elsif ($f eq 'l' and not $posix) { } 4 41 45
elsif ($f eq 'c') { } 1 40 41
elsif ($f eq 'C' and not $posix or $f eq 'u') { } 2 38 40
elsif ($f eq 'g' and not $posix) { } 13 25 38
elsif ($f eq 'D') { } 2 23 25
elsif ($f eq 'r') { } 1 22 23
elsif ($f eq 'R') { } 1 21 22
elsif ($f eq 'T' or $f eq 'X') { } 2 19 21
elsif ($f eq 'V' and not $posix) { } 1 18 19
elsif ($f eq 'Q') { } 1 17 18
elsif ($f eq 'q') { } 1 16 17
elsif ($f eq 'P' and not $posix) { } 1 15 16
elsif ($f eq 'O') { } 1 14 15
elsif ($f eq 'F') { } 2 12 14
elsif ($f eq 'K') { } 1 11 12
elsif ($f eq 'x') { } 2 9 11
elsif ($f eq 'J') { } 9 0 9
elsif ($f eq 'n') { } 0 0 0
elsif ($f eq 't') { } 0 0 0
Condition100%9/9
not $posix and exists $num{$f} or $posix and exists $num_pos{$f}
l!l&&r!l&&!r
17231144
not $posix and exists $num{$f}
!ll&&!rl&&r
41134172
$posix and exists $num_pos{$f}
!ll&&!rl&&r
1341031
MC/DC75%3/4
not $posix and exists $num{$f} or $posix and exists $num_pos{$f}
not $posix exists $num{$f} $posix exists $num_pos{$f}
Truth table57%4/7
not(A) and B or C and D
A= not $posixB= exists $num{$f}C= $posixD= exists $num_pos{$f}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
4683 ($posix && exists $num_pos{$f})) {
4684 203 ▶ while (length($val) < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $val < $len) 120 203 323
4685 120 $val = "$pad$val";
4686 }
4687  
4688 203 ▶ $val = substr($val,2,2) if ($f eq 'y');
Branch: 1 branch
BranchTrueFalseTotal
if $f eq "y" 5 198 203
4689  
4690 ▶ } elsif ($f eq 'b' || $f eq 'h') {
Condition100%3/3
$f eq "b" or $f eq "h"
l!l&&r!l&&!r
222120
MC/DC100%2/2
$f eq "b" or $f eq "h"
$f eq "b" $f eq "h"
Truth table100%3/3
A or B
A= $f eq "b"B= $f eq "h"
ABresult
1X1
011
000
4691 24 $val = $$dmb{'data'}{'wordlist'}{'month_abb'}[$m-1];
4692  
4693 } elsif ($f eq 'B') {
4694 3 $val = $$dmb{'data'}{'wordlist'}{'month_name'}[$m-1];
4695  
4696 } elsif ($f eq 'v') {
4697 2 $val = $$dmb{'data'}{'wordlist'}{'day_char'}[$dow-1];
4698  
4699 } elsif ($f eq 'a') {
4700 18 $val = $$dmb{'data'}{'wordlist'}{'day_abb'}[$dow-1];
4701  
4702 } elsif ($f eq 'A') {
4703 3 $val = $$dmb{'data'}{'wordlist'}{'day_name'}[$dow-1];
4704  
4705 } elsif ($f eq 'w') {
4706 11 $val = $dow;
4707  
4708 ▶ } elsif ($f eq 'p' || ($f eq 'P' && $posix)) {
Condition100%6/6
$f eq "p" or $f eq "P" and $posix
l!l&&r!l&&!r
4178
$f eq "P" and $posix
!ll&&!rl&&r
7711
MC/DC100%3/3
$f eq "p" or $f eq "P" and $posix
$f eq "p" $f eq "P" $posix
Truth table100%4/4
A or B and C
A= $f eq "p"B= $f eq "P"C= $posix
ABCresult
1XX1
0111
00X0
0100
4709 5 ▶ my $i = ($h >= 12 ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$h >= 12 ? : 1 4 5
4710 5 $val = $$dmb{'data'}{'wordlist'}{'ampm'}[$i];
4711 5 ▶ $val = lc($val) if ($f eq 'P');
Branch: 1 branch
BranchTrueFalseTotal
if $f eq "P" 1 4 5
4712  
4713 } elsif ($f eq 'Z') {
4714 19 $val = $$self{'data'}{'abb'};
4715  
4716 } elsif ($f eq 'N') {
4717 4 my $off = $$self{'data'}{'offset'};
4718 4 $val = $dmb->join('offset',$off);
4719  
4720 } elsif ($f eq 'z') {
4721 4 my $off = $$self{'data'}{'offset'};
4722 4 $val = $dmb->join('offset',$off);
4723 4 $val =~ s/://g;
4724 4 $val =~ s/00$//;
4725  
4726 } elsif ($f eq 'E') {
4727 2 $val = $$dmb{'data'}{'wordlist'}{'nth_dom'}[$d-1];
4728  
4729 } elsif ($f eq 's') {
4730 2 $val = $self->secs_since_1970_GMT();
4731  
4732 } elsif ($f eq 'o') {
4733 2 my $date2 = $self->new_date();
4734 2 $date2->parse('1970-01-01 00:00:00');
4735 2 my $delta = $date2->calc($self);
4736 2 $val = $delta->printf('%sys');
4737  
4738 ▶ } elsif ($f eq 'l' && ! $posix) {
Condition66%2/3
$f eq "l" and not $posix
!ll&&!rl&&r
4104
MC/DC50%1/2
$f eq "l" and not $posix
$f eq "l" not $posix
Truth table66%2/3
A and not(B)
A= $f eq "l"B= not $posix
ABresult
0X0
100
111
4739 4 my $d0 = $self->new_date();
4740 4 my $d1 = $self->new_date();
4741 4 $d0->parse('-0:6:0:0:0:0:0'); # 6 months ago
4742 4 $d1->parse('+0:6:0:0:0:0:0'); # in 6 months
4743 4 $d0 = $d0->value();
4744 4 $d1 = $d1->value();
4745 4 my $date = $self->value();
4746 4 ▶ if ($date lt $d0 || $date ge $d1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date lt $d0 or $date ge $d1) { } 2 2 4
Condition100%3/3
$date lt $d0 or $date ge $d1
l!l&&r!l&&!r
112
MC/DC100%2/2
$date lt $d0 or $date ge $d1
$date lt $d0 $date ge $d1
Truth table100%3/3
A or B
A= $date lt $d0B= $date ge $d1
ABresult
1X1
011
000
4747 2 $in = '%b %e %Y' . $in;
4748 } else {
4749 2 $in = '%b %e %H:%M' . $in;
4750 }
4751 4 $val = '';
4752  
4753 } elsif ($f eq 'c') {
4754 1 $in = '%a %b %e %H:%M:%S %Y' . $in;
4755 1 $val = '';
4756  
4757 ▶ } elsif (($f eq 'C' && ! $posix) || $f eq 'u') {
Condition83%5/6
$f eq "C" and not $posix or $f eq "u"
l!l&&r!l&&!r
1138
$f eq "C" and not $posix
!ll&&!rl&&r
3901
MC/DC66%2/3
$f eq "C" and not $posix or $f eq "u"
$f eq "C" not $posix $f eq "u"
Truth table60%3/5
A and not(B) or C
A= $f eq "C"B= not $posixC= $f eq "u"
ABCresult
11X1
0X11
1011
0X00
1000
4758 2 $in = '%a %b %e %H:%M:%S %Z %Y' . $in;
4759 2 $val = '';
4760  
4761 ▶ } elsif ($f eq 'g' && ! $posix) {
Condition66%2/3
$f eq "g" and not $posix
!ll&&!rl&&r
25013
MC/DC50%1/2
$f eq "g" and not $posix
$f eq "g" not $posix
Truth table66%2/3
A and not(B)
A= $f eq "g"B= not $posix
ABresult
0X0
100
111
4762 13 $in = '%a, %d %b %Y %H:%M:%S %Z' . $in;
4763 13 $val = '';
4764  
4765 } elsif ($f eq 'D') {
4766 2 $in = '%m/%d/%y' . $in;
4767 2 $val = '';
4768  
4769 } elsif ($f eq 'r') {
4770 1 $in = '%I:%M:%S %p' . $in;
4771 1 $val = '';
4772  
4773 } elsif ($f eq 'R') {
4774 1 $in = '%H:%M' . $in;
4775 1 $val = '';
4776  
4777 ▶ } elsif ($f eq 'T' || $f eq 'X') {
Condition100%3/3
$f eq "T" or $f eq "X"
l!l&&r!l&&!r
1119
MC/DC100%2/2
$f eq "T" or $f eq "X"
$f eq "T" $f eq "X"
Truth table100%3/3
A or B
A= $f eq "T"B= $f eq "X"
ABresult
1X1
011
000
4778 2 $in = '%H:%M:%S' . $in;
4779 2 $val = '';
4780  
4781 ▶ } elsif ($f eq 'V' && ! $posix) {
Condition66%2/3
$f eq "V" and not $posix
!ll&&!rl&&r
1801
MC/DC50%1/2
$f eq "V" and not $posix
$f eq "V" not $posix
Truth table66%2/3
A and not(B)
A= $f eq "V"B= not $posix
ABresult
0X0
100
111
4782 1 $in = '%m%d%H%M%y' . $in;
4783 1 $val = '';
4784  
4785 } elsif ($f eq 'Q') {
4786 1 $in = '%Y%m%d' . $in;
4787 1 $val = '';
4788  
4789 } elsif ($f eq 'q') {
4790 1 $in = '%Y%m%d%H%M%S' . $in;
4791 1 $val = '';
4792  
4793 ▶ } elsif ($f eq 'P' && ! $posix) {
Condition66%2/3
$f eq "P" and not $posix
!ll&&!rl&&r
1501
MC/DC50%1/2
$f eq "P" and not $posix
$f eq "P" not $posix
Truth table66%2/3
A and not(B)
A= $f eq "P"B= not $posix
ABresult
0X0
100
111
4794 1 $in = '%Y%m%d%H:%M:%S' . $in;
4795 1 $val = '';
4796  
4797 } elsif ($f eq 'O') {
4798 1 $in = '%Y-%m-%dT%H:%M:%S' . $in;
4799 1 $val = '';
4800  
4801 } elsif ($f eq 'F') {
4802 2 ▶ if ($posix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($posix) { } 1 1 2
4803 1 $in = '%Y-%m-%d' . $in;
4804 } else {
4805 1 $in = '%A, %B %e, %Y' . $in;
4806 }
4807 2 $val = '';
4808  
4809 } elsif ($f eq 'K') {
4810 1 $in = '%Y-%j' . $in;
4811 1 $val = '';
4812  
4813 } elsif ($f eq 'x') {
4814 2 ▶ if ($dmb->_config('dateformat') eq 'US') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dmb->_config('dateformat') eq 'US') { } 1 1 2
4815 1 $in = '%m/%d/%y' . $in;
4816 } else {
4817 1 $in = '%d/%m/%y' . $in;
4818 }
4819 2 $val = '';
4820  
4821 } elsif ($f eq 'J') {
4822 9 ▶ if ($posix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($posix) { } 4 5 9
4823 4 $in = '%G-W%V-%w' . $in;
4824 } else {
4825 5 $in = '%G-W%W-%w' . $in;
4826 }
4827 9 $val = '';
4828  
4829 } elsif ($f eq 'n') {
4830 0 $val = "\n";
4831  
4832 } elsif ($f eq 't') {
4833 0 $val = "\t";
4834  
4835 } else {
4836 0 $val = $f;
4837 }
4838  
4839 347 ▶ if ($val ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($val ne "") 302 45 347
4840 302 $$self{'data'}{'f'}{$f} = $val;
4841 302 $out .= $val;
4842 }
4843 }
4844 63 push(@out,$out);
4845 }
4846  
4847 61 ▶ if (wantarray) {
Branch: 2 branches
BranchTrueFalseTotal
if (wantarray) { } 49 12 61
elsif (@out == 1) { } 12 0 12
4848 49 return @out;
4849 } elsif (@out == 1) {
4850 12 return $out[0];
4851 }
4852  
4853 0 return ''
4854 }
4855 }
4856  
4857 ########################################################################
4858 # EVENT METHODS
4859  
4860 21 ▶sub list_events {
Subroutine list_events: called CC=42 SCAR=38.0
Pod documented
4861 21 my($self,@args) = @_;
4862 21 ▶ if ($$self{'err'} || ! $$self{'data'}{'set'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"err"} or not $self->{"data"}{"set"}) 0 21 21
Condition33%1/3
$self->{"err"} or not $self->{"data"}{"set"}
l!l&&r!l&&!r
0021
MC/DC0%0/2
$self->{"err"} or not $self->{"data"}{"set"}
$self->{"err"} not $self->{"data"}{"set"}
Truth table33%1/3
A or not(B)
A= $self->{"err"}B= not $self->{"data"}{"set"}
ABresult
1X1
011
000
4863 0 carp "WARNING: [list_events] Object must contain a valid date";
4864 0 return undef;
4865 }
4866 21 my $dmt = $$self{'tz'};
4867 21 my $dmb = $$dmt{'base'};
4868  
4869 # Arguments
4870  
4871 21 my($date,$day,$format);
4872 21 ▶ if (@args && $args[$#args] eq 'dates') {
Branch: 1 branch
BranchTrueFalseTotal
if (@args and $args[$#args] eq 'dates') { } 9 12 21
Condition100%3/3
@args and $args[$#args] eq "dates"
!ll&&!rl&&r
1119
MC/DC100%2/2
@args and $args[$#args] eq "dates"
@args $args[$#args] eq "dates"
Truth table100%3/3
A and B
A= @argsB= $args[$#args] eq "dates"
ABresult
0X0
100
111
4873 9 pop(@args);
4874 9 $format = 'dates';
4875 } else {
4876 12 $format = 'std';
4877 }
4878  
4879 21 ▶ if (@args && $#args==0 && ref($args[0]) eq 'Date::Manip::Date') {
Branch: 3 branches
BranchTrueFalseTotal
if (@args and $#args == 0 and ref $args[0] eq 'Date::Manip::Date') { } 4 17 21
elsif (@args and $#args == 0 and $args[0] == 0) { } 2 15 17
elsif (@args) { } 0 15 15
Condition83%5/6
@args and $#args == 0 and ref $args[0] eq "Date::Manip::Date"
!ll&&!rl&&r
1524
@args and $#args == 0
!ll&&!rl&&r
1506
MC/DC66%2/3
@args and $#args == 0 and ref $args[0] eq "Date::Manip::Date"
@args $#args == 0 ref $args[0] eq "Date::Manip::Date"
Truth table75%3/4
A and B and C
A= @argsB= $#args == 0C= ref $args[0] eq "Date::Manip::Date"
ABCresult
0XX0
10X0
1100
1111
4880 4 $date = $args[0];
4881 ▶ } elsif (@args && $#args==0 && $args[0]==0) {
Condition66%4/6
@args and $#args == 0 and $args[0] == 0
!ll&&!rl&&r
1502
@args and $#args == 0
!ll&&!rl&&r
1502
MC/DC33%1/3
@args and $#args == 0 and $args[0] == 0
@args $#args == 0 $args[0] == 0
Truth table50%2/4
A and B and C
A= @argsB= $#args == 0C= $args[0] == 0
ABCresult
0XX0
10X0
1100
1111
4882 2 $day = 1;
4883 } elsif (@args) {
4884 0 carp "ERROR: [list_events] unknown argument list";
4885 0 return [];
4886 }
4887  
4888 # Get the beginning/end dates we're looking for events in
4889  
4890 21 my($beg,$end);
4891 21 ▶ if ($date) {
Branch: 2 branches
BranchTrueFalseTotal
if ($date) { } 4 17 21
elsif ($day) { } 2 15 17
4892 4 $beg = $self;
4893 4 $end = $date;
4894 } elsif ($day) {
4895 2 $beg = $self->new_date();
4896 2 $end = $self->new_date();
4897 2 my($y,$m,$d) = $self->value();
4898 2 $beg->set('date',[$y,$m,$d,0,0,0]);
4899 2 $end->set('date',[$y,$m,$d,23,59,59]);
4900 } else {
4901 15 $beg = $self;
4902 15 $end = $self;
4903 }
4904  
4905 21 ▶ if ($beg->cmp($end) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($beg->cmp($end) == 1) 0 21 21
4906 0 my $tmp = $beg;
4907 0 $beg = $end;
4908 0 $end = $tmp;
4909 }
4910  
4911 # We need to get a list of all events which may apply.
4912  
4913 21 my($y0) = $beg->value();
4914 21 my($y1) = $end->value();
4915 21 foreach my $y ($y0..$y1) {
4916 21 $self->_events_year($y);
4917 }
4918  
4919 21 my @events = ();
4920 21 foreach my $i (keys %{ $$dmb{'data'}{'events'} }) {
4921 231 my $event = $$dmb{'data'}{'events'}{$i};
4922 231 my $type = $$event{'type'};
4923 231 my $name = $$event{'name'};
4924  
4925 231 ▶ if ($type eq 'specified') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'specified') { } 129 102 231
elsif ($type eq 'ym' or $type eq 'date') { } 52 50 102
elsif ($type eq 'recur') { } 50 0 50
4926 129 my $d0 = $$dmb{'data'}{'events'}{$i}{'beg'};
4927 129 my $d1 = $$dmb{'data'}{'events'}{$i}{'end'};
4928 129 push @events,[$d0,$d1,$name];
4929  
4930 ▶ } elsif ($type eq 'ym' || $type eq 'date') {
Condition100%3/3
$type eq "ym" or $type eq "date"
l!l&&r!l&&!r
262650
MC/DC100%2/2
$type eq "ym" or $type eq "date"
$type eq "ym" $type eq "date"
Truth table100%3/3
A or B
A= $type eq "ym"B= $type eq "date"
ABresult
1X1
011
000
4931 52 foreach my $y ($y0..$y1) {
4932 52 ▶ if (exists $$dmb{'data'}{'events'}{$i}{$y}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dmb->{"data"}{"events"}{$i}{$y}) 52 0 52
4933 52 my($d0,$d1) = @{ $$dmb{'data'}{'events'}{$i}{$y} };
4934 52 push @events,[$d0,$d1,$name];
4935 }
4936 }
4937  
4938 } elsif ($type eq 'recur') {
4939 50 my $rec = $$dmb{'data'}{'events'}{$i}{'recur'};
4940 50 my $del = $$dmb{'data'}{'events'}{$i}{'delta'};
4941 50 my @d = $rec->dates($beg,$end);
4942 50 foreach my $d0 (@d) {
4943 4 my $d1 = $d0->calc($del);
4944 4 push @events,[$d0,$d1,$name];
4945 }
4946 }
4947 }
4948  
4949 # Next we need to see which ones apply.
4950  
4951 21 my @tmp;
4952 21 foreach my $e (@events) {
4953 185 my($d0,$d1,$name) = @$e;
4954  
4955 185 ▶ push(@tmp,$e) if ($beg->cmp($d1) != 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if $beg->cmp($d1) != 1 and $end->cmp($d0) != -1 48 137 185
Condition100%3/3
$beg->cmp($d1) != 1 and $end->cmp($d0) != -1
!ll&&!rl&&r
558248
MC/DC100%2/2
$beg->cmp($d1) != 1 and $end->cmp($d0) != -1
$beg->cmp($d1) != 1 $end->cmp($d0) != -1
Truth table100%3/3
A and B
A= $beg->cmp($d1) != 1B= $end->cmp($d0) != -1
ABresult
0X0
100
111
4956 $end->cmp($d0) != -1);
4957 }
4958  
4959 # Now format them...
4960  
4961 21 ▶ if ($format eq 'std') {
Branch: 2 branches
BranchTrueFalseTotal
if ($format eq 'std') { } 12 9 21
elsif ($format eq 'dates') { } 9 0 9
4962 12 ▶ @events = sort { $$a[0]->cmp($$b[0]) ||
Condition83%5/6
$Date::Manip::Date::a->[0]->cmp($Date::Manip::Date::b->[0]) || $Date::Manip::Date::a->[1]->cmp($Date::Manip::Date::b->[1]) || $Date::Manip::Date::a->[2] cmp $Date::Manip::Date::b->[2]
l!l&&r!l&&!r
1180
$Date::Manip::Date::a->[0]->cmp($Date::Manip::Date::b->[0]) or $Date::Manip::Date::a->[1]->cmp($Date::Manip::Date::b->[1])
l!l&&r!l&&!r
838
MC/DC0%0/3
$Date::Manip::Date::a->[0]->cmp($Date::Manip::Date::b->[0]) || $Date::Manip::Date::a->[1]->cmp($Date::Manip::Date::b->[1]) || $Date::Manip::Date::a->[2] cmp $Date::Manip::Date::b->[2]
$Date::Manip::Date::a->[0]->cmp($Date::Manip::Date::b->[0]) $Date::Manip::Date::a->[1]->cmp($Date::Manip::Date::b->[1]) $Date::Manip::Date::a->[2] cmp $Date::Manip::Date::b->[2]
Truth table75%3/4
A or B || C
A= $Date::Manip::Date::a->[0]->cmp($Date::Manip::Date::b->[0])B= $Date::Manip::Date::a->[1]->cmp($Date::Manip::Date::b->[1])C= $Date::Manip::Date::a->[2] cmp $Date::Manip::Date::b->[2]
ABCresult
1XX1
01X1
0011
0000
4963 $$a[1]->cmp($$b[1]) ||
4964 $$a[2] cmp $$b[2] } @tmp;
4965  
4966 } elsif ($format eq 'dates') {
4967 9 my $p1s = $self->new_delta();
4968 9 $p1s->parse('+0:0:0:0:0:0:1');
4969  
4970 9 @events = ();
4971 9 my (@tmp2);
4972 9 foreach my $e (@tmp) {
4973 22 my $name = $$e[2];
4974 22 ▶ if ($$e[0]->cmp($beg) == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->[0]->cmp($beg) == -1) { } 9 13 22
4975 # Event begins before the start
4976 9 push(@tmp2,[$beg,'+',$name]);
4977 } else {
4978 13 push(@tmp2,[$$e[0],'+',$name]);
4979 }
4980  
4981 22 my $d1 = $$e[1]->calc($p1s);
4982  
4983 22 ▶ if ($d1->cmp($end) == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d1->cmp($end) == -1) 12 10 22
4984 # Event ends before the end
4985 12 push(@tmp2,[$d1,'-',$name]);
4986 }
4987 }
4988  
4989 9 ▶ return () if (! @tmp2);
Branch: 1 branch
BranchTrueFalseTotal
unless @tmp2 0 9 9
4990 9 ▶ @tmp2 = sort { $$a[0]->cmp($$b[0]) ||
Condition83%5/6
$Date::Manip::Date::a->[0]->cmp($Date::Manip::Date::b->[0]) || $Date::Manip::Date::a->[1] cmp $Date::Manip::Date::b->[1] || $Date::Manip::Date::a->[2] cmp $Date::Manip::Date::b->[2]
l!l&&r!l&&!r
4360
$Date::Manip::Date::a->[0]->cmp($Date::Manip::Date::b->[0]) or $Date::Manip::Date::a->[1] cmp $Date::Manip::Date::b->[1]
l!l&&r!l&&!r
4036
MC/DC0%0/3
$Date::Manip::Date::a->[0]->cmp($Date::Manip::Date::b->[0]) || $Date::Manip::Date::a->[1] cmp $Date::Manip::Date::b->[1] || $Date::Manip::Date::a->[2] cmp $Date::Manip::Date::b->[2]
$Date::Manip::Date::a->[0]->cmp($Date::Manip::Date::b->[0]) $Date::Manip::Date::a->[1] cmp $Date::Manip::Date::b->[1] $Date::Manip::Date::a->[2] cmp $Date::Manip::Date::b->[2]
Truth table75%3/4
A or B || C
A= $Date::Manip::Date::a->[0]->cmp($Date::Manip::Date::b->[0])B= $Date::Manip::Date::a->[1] cmp $Date::Manip::Date::b->[1]C= $Date::Manip::Date::a->[2] cmp $Date::Manip::Date::b->[2]
ABCresult
1XX1
01X1
0011
0000
4991 $$a[1] cmp $$b[1] ||
4992 $$a[2] cmp $$b[2] } @tmp2;
4993  
4994 # @tmp2 is now:
4995 # ( [ DATE1, OP1, NAME1 ], [ DATE2, OP2, NAME2 ], ... )
4996 # which is sorted by date.
4997  
4998 9 my $d = $tmp2[0]->[0];
4999  
5000 9 ▶ if ($beg->cmp($d) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($beg->cmp($d) != 0) 1 8 9
5001 1 push(@events,[$beg]);
5002 }
5003  
5004 9 my %e;
5005 9 while (1) {
5006  
5007 # If the first element is the same date as we're
5008 # currently working with, just perform the operation
5009 # and remove it from the list. If the list is not empty,
5010 # we'll proceed to the next element.
5011  
5012 50 my $d0 = $tmp2[0]->[0];
5013 50 ▶ if ($d->cmp($d0) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d->cmp($d0) == 0) 34 16 50
5014 34 my $e = shift(@tmp2);
5015 34 my $op = $$e[1];
5016 34 my $n = $$e[2];
5017 34 ▶ if ($op eq '+') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq '+') { } 22 12 34
5018 22 $e{$n} = 1;
5019 } else {
5020 12 delete $e{$n};
5021 }
5022  
5023 34 ▶ next if (@tmp2);
Branch: 1 branch
BranchTrueFalseTotal
if @tmp2 25 9 34
5024 }
5025  
5026 # We need to store the existing %e.
5027  
5028 25 my @n = sort keys %e;
5029 25 push(@events,[$d,@n]);
5030  
5031 # If the list is empty, we're done. Otherwise, we need to
5032 # reset the date and continue.
5033  
5034 25 ▶ last if (! @tmp2);
Branch: 1 branch
BranchTrueFalseTotal
unless @tmp2 9 16 25
5035 16 $d = $tmp2[0]->[0];
5036 }
5037 }
5038  
5039 21 return @events;
5040 }
5041  
5042 # The events of type date and ym are determined on a year-by-year basis
5043 #
5044 21 ▶sub _events_year {
Subroutine _events_year: called CC=9 SCAR=22.1
5045 21 my($self,$y) = @_;
5046 21 my $dmt = $$self{'tz'};
5047 21 my $dmb = $$dmt{'base'};
5048 21 my $tz = $dmt->_now('tz',1);
5049 21 ▶ return if (exists $$dmb{'data'}{'eventyears'}{$y});
Branch: 1 branch
BranchTrueFalseTotal
if exists $dmb->{"data"}{"eventyears"}{$y} 0 21 21
5050 21 ▶ $self->_event_objs() if (! $$dmb{'data'}{'eventobjs'});
Branch: 1 branch
BranchTrueFalseTotal
unless $dmb->{"data"}{"eventobjs"} 3 18 21
5051  
5052 21 my $d = $self->new_date();
5053 21 $d->config('forcedate',"${y}-01-01-00:00:00,$tz");
5054  
5055 21 my $hrM1 = $d->new_delta();
5056 21 $hrM1->set('delta',[0,0,0,0,0,59,59]);
5057  
5058 21 my $dayM1 = $d->new_delta();
5059 21 $dayM1->set('delta',[0,0,0,0,23,59,59]);
5060  
5061 21 foreach my $i (keys %{ $$dmb{'data'}{'events'} }) {
5062 231 my $event = $$dmb{'data'}{'events'}{$i};
5063 231 my $type = $$event{'type'};
5064  
5065 231 ▶ if ($type eq 'ym') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'ym') { } 26 205 231
elsif ($type eq 'date') { } 26 179 205
5066 26 my $beg = $$event{'beg'};
5067 26 my $end = $$event{'end'};
5068 26 my $d0 = $d->new_date();
5069 26 $d0->parse_date($beg);
5070 26 $d0->set('time',[0,0,0]);
5071  
5072 26 my $d1;
5073 26 ▶ if ($end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end) { } 13 13 26
5074 13 $d1 = $d0->new_date();
5075 13 $d1->parse_date($end);
5076 13 $d1->set('time',[23,59,59]);
5077 } else {
5078 13 $d1 = $d0->calc($dayM1);
5079 }
5080 26 $$dmb{'data'}{'events'}{$i}{$y} = [ $d0,$d1 ];
5081  
5082 } elsif ($type eq 'date') {
5083 26 my $beg = $$event{'beg'};
5084 26 my $end = $$event{'end'};
5085 26 my $del = $$event{'delta'};
5086 26 my $d0 = $d->new_date();
5087 26 $d0->parse($beg);
5088  
5089 26 my $d1;
5090 26 ▶ if ($end) {
Branch: 2 branches
BranchTrueFalseTotal
if ($end) { } 0 26 26
elsif ($del) { } 26 0 26
5091 0 $d1 = $d0->new_date();
5092 0 $d1->parse($end);
5093 } elsif ($del) {
5094 26 $d1 = $d0->calc($del);
5095 } else {
5096 0 $d1 = $d0->calc($hrM1);
5097 }
5098 26 $$dmb{'data'}{'events'}{$i}{$y} = [ $d0,$d1 ];
5099 }
5100 }
5101  
5102 21 return;
5103 }
5104  
5105 # This parses the raw event list. It only has to be done once.
5106 #
5107 3 ▶sub _event_objs {
Subroutine _event_objs: called CC=25 SCAR=34.5
5108 3 my($self) = @_;
5109 3 my $dmt = $$self{'tz'};
5110 3 my $dmb = $$dmt{'base'};
5111 # Only parse once.
5112 3 $$dmb{'data'}{'eventobjs'} = 1;
5113  
5114 3 my $hrM1 = $self->new_delta();
5115 3 $hrM1->set('delta',[0,0,0,0,0,59,59]);
5116  
5117 3 my $M1 = $self->new_delta();
5118 3 $M1->set('delta',[0,0,0,0,0,0,-1]);
5119  
5120 3 my @tmp = @{ $$dmb{'data'}{'sections'}{'events'} };
5121 3 my $i = 0;
5122 3 ▶ while (@tmp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tmp) 33 3 36
5123 33 my $string = shift(@tmp);
5124 33 my $name = shift(@tmp);
5125 33 my @event = split(/\s*;\s*/,$string);
5126  
5127 33 ▶ if ($#event == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($#event == 0) { } 15 18 33
elsif ($#event == 1) { } 18 0 18
5128  
5129 # YMD/YM
5130  
5131 15 my $d1 = $self->new_date();
5132 15 my $err = $d1->parse_date($event[0]);
5133 15 ▶ if (! $err) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 6 9 15
5134 6 ▶ if ($$d1{'data'}{'def'}[0] eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($d1->{'data'}{'def'}[0] eq '') { } 2 4 6
5135 # YM
5136 2 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'ym',
5137 'name' => $name,
5138 'beg' => $event[0] };
5139 } else {
5140 # YMD
5141 4 my $d2 = $d1->new_date();
5142 4 my ($y,$m,$d) = $d1->value();
5143 4 $d1->set('time',[0,0,0]);
5144 4 $d2->set('date',[$y,$m,$d,23,59,59]);
5145 4 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'specified',
5146 'name' => $name,
5147 'beg' => $d1,
5148 'end' => $d2 };
5149 }
5150 6 next;
5151 }
5152  
5153 # Date
5154  
5155 9 $err = $d1->parse($event[0]);
5156 9 ▶ if (! $err) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 5 4 9
5157 5 ▶ if ($$d1{'data'}{'def'}[0] eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($d1->{'data'}{'def'}[0] eq '') { } 2 3 5
5158 # Date (no year)
5159 2 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'date',
5160 'name' => $name,
5161 'beg' => $event[0],
5162 'delta' => $hrM1
5163 };
5164 } else {
5165 # Date (year)
5166 3 my $d2 = $d1->calc($hrM1);
5167 3 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'specified',
5168 'name' => $name,
5169 'beg' => $d1,
5170 'end' => $d2
5171 };
5172 }
5173 5 next;
5174 }
5175  
5176 # Recur
5177  
5178 4 my $r = $self->new_recur();
5179 4 $err = $r->parse($event[0]);
5180 4 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 4 4
5181 0 carp "ERROR: invalid event definition (must be Date, YMD, YM, or Recur)\n"
5182 . " $string\n";
5183 0 next;
5184 }
5185  
5186 4 my @d = $r->dates();
5187 4 ▶ if (@d) {
Branch: 1 branch
BranchTrueFalseTotal
if (@d) { } 0 4 4
5188 0 foreach my $d (@d) {
5189 0 my $d2 = $d->calc($hrM1);
5190 0 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'specified',
5191 'name' => $name,
5192 'beg' => $d1,
5193 'end' => $d2
5194 };
5195 }
5196 } else {
5197 4 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'recur',
5198 'name' => $name,
5199 'recur' => $r,
5200 'delta' => $hrM1
5201 };
5202 }
5203  
5204 } elsif ($#event == 1) {
5205 18 my($o1,$o2) = @event;
5206  
5207 # YMD;YMD
5208 # YM;YM
5209  
5210 18 my $d1 = $self->new_date();
5211 18 my $err = $d1->parse_date($o1);
5212 18 ▶ if (! $err) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 9 9 18
5213 9 my $d2 = $self->new_date();
5214 9 $err = $d2->parse_date($o2);
5215 9 ▶ if ($err) {
Branch: 2 branches
BranchTrueFalseTotal
if ($err) { } 0 9 9
elsif ($d1->{'data'}{'def'}[0] ne $d2->{'data'}{'def'}[0]) { } 0 9 9
5216 0 carp "ERROR: invalid event definition (must be YMD;YMD or YM;YM)\n"
5217 . " $string\n";
5218 0 next;
5219 } elsif ($$d1{'data'}{'def'}[0] ne $$d2{'data'}{'def'}[0]) {
5220 0 carp "ERROR: invalid event definition (YMD;YM or YM;YMD not allowed)\n"
5221 . " $string\n";
5222 0 next;
5223 }
5224  
5225 9 ▶ if ($$d1{'data'}{'def'}[0] eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($d1->{'data'}{'def'}[0] eq '') { } 2 7 9
5226 # YM;YM
5227 2 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'ym',
5228 'name' => $name,
5229 'beg' => $o1,
5230 'end' => $o2
5231 };
5232 } else {
5233 # YMD;YMD
5234 7 $d1->set('time',[0,0,0]);
5235 7 $d2->set('time',[23,59,59]);
5236 7 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'specified',
5237 'name' => $name,
5238 'beg' => $d1,
5239 'end' => $d2 };
5240 }
5241 9 next;
5242 }
5243  
5244 # Date;Date
5245 # Date;Delta
5246  
5247 9 $err = $d1->parse($o1);
5248 9 ▶ if (! $err) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 6 3 9
5249  
5250 6 my $d2 = $self->new_date();
5251 6 $err = $d2->parse($o2,'nodelta');
5252  
5253 6 ▶ if (! $err) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 2 4 6
5254 # Date;Date
5255 2 ▶ if ($$d1{'data'}{'def'}[0] ne $$d2{'data'}{'def'}[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d1->{"data"}{"def"}[0] ne $d2->{"data"}{"def"}[0]) 0 2 2
5256 0 carp "ERROR: invalid event definition (year must be absent or\n"
5257 . " included in both dats in Date;Date)\n"
5258 . " $string\n";
5259 0 next;
5260 }
5261  
5262 2 ▶ if ($$d1{'data'}{'def'}[0] eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($d1->{'data'}{'def'}[0] eq '') { } 0 2 2
5263 # Date (no year)
5264 0 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'date',
5265 'name' => $name,
5266 'beg' => $o1,
5267 'end' => $o2
5268 };
5269 } else {
5270 # Date (year)
5271 2 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'specified',
5272 'name' => $name,
5273 'beg' => $d1,
5274 'end' => $d2
5275 };
5276 }
5277 2 next;
5278 }
5279  
5280 # Date;Delta
5281 4 my $del = $self->new_delta();
5282 4 $err = $del->parse($o2);
5283  
5284 4 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 4 4
5285 0 carp "ERROR: invalid event definition (must be Date;Date or\n"
5286 . " Date;Delta) $string\n";
5287 0 next;
5288 }
5289  
5290 4 $del = $del->calc($M1);
5291 4 ▶ if ($$d1{'data'}{'def'}[0] eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($d1->{'data'}{'def'}[0] eq '') { } 2 2 4
5292 # Date (no year)
5293 2 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'date',
5294 'name' => $name,
5295 'beg' => $o1,
5296 'delta' => $del
5297 };
5298 } else {
5299 # Date (year)
5300 2 $d2 = $d1->calc($del);
5301 2 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'specified',
5302 'name' => $name,
5303 'beg' => $d1,
5304 'end' => $d2
5305 };
5306 }
5307 4 next;
5308 }
5309  
5310 # Recur;Delta
5311  
5312 3 my $r = $self->new_recur();
5313 3 $err = $r->parse($o1);
5314  
5315 3 my $del = $self->new_delta();
5316 3 ▶ if (! $err) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 3 0 3
5317 3 $err = $del->parse($o2);
5318 }
5319  
5320 3 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 3 3
5321 0 carp "ERROR: invalid event definition (must be Date;Date, YMD;YMD, "
5322 . " YM;YM, Date;Delta, or Recur;Delta)\n"
5323 . " $string\n";
5324 0 next;
5325 }
5326  
5327 3 $del = $del->calc($M1);
5328 3 my @d = $r->dates();
5329 3 ▶ if (@d) {
Branch: 1 branch
BranchTrueFalseTotal
if (@d) { } 0 3 3
5330 0 foreach my $d1 (@d) {
5331 0 my $d2 = $d1->calc($del);
5332 0 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'specified',
5333 'name' => $name,
5334 'beg' => $d1,
5335 'end' => $d2
5336 };
5337 }
5338 } else {
5339 3 $$dmb{'data'}{'events'}{$i++} = { 'type' => 'recur',
5340 'name' => $name,
5341 'recur' => $r,
5342 'delta' => $del
5343 };
5344 }
5345  
5346 } else {
5347 0 carp "ERROR: invalid event definition\n"
5348 . " $string\n";
5349 0 next;
5350 }
5351 }
5352  
5353 3 return;
5354 }
5355  
5356 170 1;
5357 # Local Variables:
5358 # mode: cperl
5359 # indent-tabs-mode: nil
5360 # cperl-indent-level: 3
5361 # cperl-continued-statement-offset: 2
5362 # cperl-continued-brace-offset: 0
5363 # cperl-brace-offset: 0
5364 # cperl-brace-imaginary-offset: 0
5365 # cperl-label-offset: 0
5366 # End:
« lib/Date/Manip/TZdata.pm ↑ Summary lib/Date/Manip/Recur.pm »