lib/Date/Manip/Date.pm

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