lib/Date/Manip/DM6.pm

filter: Statementstmt 63.2% 308 / 487 Branchbran 54.7% 163 / 298 Conditioncond 68.2% 43 / 63 MC/DCmcdc 56.7% 21 / 37 Subroutinesub 55.0% 22 / 40 Podpod 100% 34 / 34 totaltotal 61.6% 591 / 959 CC 180 SCAR 44.7
CC
180
Cov
61%
DateCalc
402.4
ParseRecur
74.9
ParseDate
72.0
CRAP 87.3
« lib/Date/Manip/Recur.pm ↑ Summary lib/Date/Manip/Delta.pm »
1 package Date::Manip::DM6;
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 ###########################################################################
8  
9 170 our (@ISA,@EXPORT);
10  
11 170 require 5.010000;
12 170 require Exporter;
13 170 @ISA = qw(Exporter);
14 170 @EXPORT = qw(
15 DateManipVersion
16 Date_Init
17 ParseDate
18 ParseDateString
19 ParseDateDelta
20 ParseDateFormat
21 ParseRecur
22 Date_IsHoliday
23 Date_IsWorkDay
24 Date_Cmp
25 DateCalc
26 UnixDate
27 Delta_Format
28 Date_GetPrev
29 Date_GetNext
30 Date_SetTime
31 Date_SetDateField
32 Events_List
33 Date_NextWorkDay
34 Date_PrevWorkDay
35 Date_NearestWorkDay
36  
37 Date_DayOfWeek
38 Date_SecsSince1970
39 Date_SecsSince1970GMT
40 Date_DaysSince1BC
41 Date_DayOfYear
42 Date_NthDayOfYear
43 Date_DaysInMonth
44 Date_DaysInYear
45 Date_WeekOfYear
46 Date_LeapYear
47 Date_DaySuffix
48 Date_ConvTZ
49 Date_TimeZone
50 );
51  
52 170 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 170 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 170 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 170 our $VERSION;
57 170 $VERSION='7.00';
58  
59 ###########################################################################
60  
61 170 our ($dmb,$dmt,$date,$delta,$recur,$date2,$dateUT);
62 170 ▶use Date::Manip::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 170 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 170 $dateUT = new Date::Manip::Date;
66 170 $dateUT->config('setdate','now,Etc/GMT');
67  
68 170 $date = new Date::Manip::Date;
69 170 $date2 = $date->new_date();
70 170 $delta = $date->new_delta();
71 170 $recur = $date->new_recur();
72 170 $dmb = $date->base();
73 170 $dmt = $date->tz();
74  
75 ########################################################################
76 ########################################################################
77 # THESE ARE THE MAIN ROUTINES
78 ########################################################################
79 ########################################################################
80  
81 170 ▶sub DateManipVersion {
Subroutine DateManipVersion: called CC=1 SCAR=0.0
Pod documented
82 170 my($flag) = @_;
83 170 return $date->version($flag);
84 }
85  
86 23 ▶sub Date_Init {
Subroutine Date_Init: called CC=3 SCAR=11.2
Pod documented
87 23 my(@args) = @_;
88 23 my(@args2);
89  
90 23 foreach my $arg (@args) {
91 24 ▶ if ($arg =~ /^(\S+)\s*=\s*(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^(\S+)\s*=\s*(.*)$/) { } 24 0 24
92 24 push(@args2,$1,$2);
93 } else {
94 0 carp "ERROR: invalid Date_Init argument: $arg";
95 }
96 }
97 23 $date->config(@args2);
98 23 return $date->err();
99 }
100  
101 247 ▶sub ParseDateString {
Subroutine ParseDateString: called CC=3 SCAR=11.0
Pod documented
102 247 my($string,@opts) = @_;
103 247 ▶ $string = '' if (! defined($string));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 247 247
104 247 my $err = $date->parse($string,@opts);
105 247 ▶ return '' if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 44 203 247
106 203 my $ret = $date->value('local');
107 203 return $ret;
108 }
109  
110 3 ▶sub ParseDateFormat {
Subroutine ParseDateFormat: called CC=3 SCAR=11.2
Pod documented
111 3 my($format,$string) = @_;
112 3 ▶ $string = '' if (! defined($string));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 3 3
113 3 my $err = $date->parse_format($format,$string);
114 3 ▶ return '' if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 3 3
115 3 my $ret = $date->value('local');
116 3 return $ret;
117 }
118  
119 0 ▶sub ParseDate {
Subroutine ParseDate: not called CC=8 SCAR=42.8
Pod documented
120 0 my($arg,@opts) = @_;
121  
122 0 ▶ $arg = '' if (! defined($arg));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 0 0 0
123 0 my $ref = ref($arg);
124 0 my $list = 0;
125  
126 0 my @args;
127 0 ▶ if (! $ref) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $ref) { } 0 0 0
elsif ($ref eq 'ARRAY') { } 0 0 0
elsif ($ref eq 'SCALAR') { } 0 0 0
128 0 @args = ($arg);
129 } elsif ($ref eq 'ARRAY') {
130 0 @args = @$arg;
131 0 $list = 1;
132 } elsif ($ref eq 'SCALAR') {
133 0 @args = ($$arg);
134 } else {
135 0 print "ERROR: Invalid arguments to ParseDate.\n";
136 0 return '';
137 }
138  
139 0 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 0 0
140 0 my $string = join(' ',@args);
141 0 my $err = $date->parse($string,@opts);
142 0 ▶ if (! $err) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 0 0 0
143 0 ▶ splice(@$arg,0,$#args+1) if ($list);
Branch: 1 branch
BranchTrueFalseTotal
if $list 0 0 0
144 0 my $ret = $date->value('local');
145 0 return $ret;
146 }
147 0 pop(@args);
148 }
149  
150 0 return '';
151 }
152  
153 33 ▶sub ParseDateDelta {
Subroutine ParseDateDelta: called CC=16 SCAR=34.2
Pod documented
154 33 my(@a) = @_;
155  
156 33 ▶ if (@a < 1 || @a > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a < 1 or @a > 2) 0 33 33
Condition33%1/3
@a < 1 or @a > 2
l!l&&r!l&&!r
0033
MC/DC0%0/2
@a < 1 or @a > 2
@a < 1 @a > 2
Truth table33%1/3
A or B
A= @a < 1B= @a > 2
ABresult
1X1
011
000
157 0 print "ERROR: Invalid number of arguments to ParseDateDelta.\n";
158 0 return '';
159 }
160 33 my($args,$mode) = @_;
161 33 ▶ $args = '' if (! defined($args));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args 0 33 33
162 33 ▶ $mode = '' if (! $mode);
Branch: 1 branch
BranchTrueFalseTotal
unless $mode 32 1 33
163 33 $mode = lc($mode);
164 33 ▶ if ($mode && ($mode ne 'exact' && $mode ne 'semi' && $mode ne 'approx')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode and ($mode ne "exact" and $mode ne "semi" and $mode ne "approx")) 0 33 33
Condition44%4/9
$mode and ($mode ne "exact" and $mode ne "semi" and $mode ne "approx")
!ll&&!rl&&r
3210
$mode ne "exact" and $mode ne "semi" and $mode ne "approx"
!ll&&!rl&&r
100
$mode ne "exact" and $mode ne "semi"
!ll&&!rl&&r
010
MC/DC0%0/4
$mode and ($mode ne "exact" and $mode ne "semi" and $mode ne "approx")
$mode $mode ne "exact" $mode ne "semi" $mode ne "approx"
Truth table40%2/5
A and B and C and D
A= $modeB= $mode ne "exact"C= $mode ne "semi"D= $mode ne "approx"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
165 0 print "ERROR: Invalid arguments to ParseDateDelta.\n";
166 0 return '';
167 }
168  
169 33 my @args;
170 33 my $ref = ref($args);
171 33 my $list = 0;
172  
173 33 ▶ if (! $ref) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $ref) { } 33 0 33
elsif ($ref eq 'ARRAY') { } 0 0 0
elsif ($ref eq 'SCALAR') { } 0 0 0
174 33 @args = ($args);
175 } elsif ($ref eq 'ARRAY') {
176 0 @args = @$args;
177 0 $list = 1;
178 } elsif ($ref eq 'SCALAR') {
179 0 @args = ($$args);
180 } else {
181 0 print "ERROR: Invalid arguments to ParseDateDelta.\n";
182 0 return '';
183 }
184  
185 33 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 33 9 42
186 33 my $string = join(' ',@args);
187 33 my $err = $delta->parse($string);
188 33 ▶ if (! $err) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 24 9 33
189 24 ▶ $delta->convert($mode) if ($mode);
Branch: 1 branch
BranchTrueFalseTotal
if $mode 1 23 24
190 24 ▶ splice(@$args,0,$#args+1) if ($list);
Branch: 1 branch
BranchTrueFalseTotal
if $list 0 24 24
191 24 my $ret = $delta->value('local');
192 24 return $ret;
193 }
194 9 pop(@args);
195 }
196  
197 9 return '';
198 }
199  
200 2 ▶sub UnixDate {
Subroutine UnixDate: called CC=4 SCAR=14.3
Pod documented
201 2 my($string,@in) = @_;
202 2 my(@ret);
203  
204 2 my $err = $date->parse($string);
205 2 ▶ return () if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 2 2
206  
207 2 foreach my $in (@in) {
208 2 push(@ret,$date->printf($in));
209 }
210  
211 2 ▶ if (! wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 0 2 2
212 0 return join(" ",@ret);
213 }
214 2 return @ret;
215 }
216  
217 19 ▶sub Delta_Format {
Subroutine Delta_Format: called CC=10 SCAR=24.2
Pod documented
218 19 my($string,@args) = @_;
219  
220 19 my $err = $delta->parse($string);
221 19 ▶ return () if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 19 19
222  
223 19 my($mode,$dec,@in);
224 19 ▶ if (! defined($args[0])) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $args[0]) { } 0 19 19
elsif (lc $args[0] eq 'exact' or lc $args[0] eq 'approx' or lc $args[0] eq 'semi') { } 18 1 19
elsif ($args[0] =~ /^\d+$/) { } 0 1 1
225 0 $mode = 'exact';
226 0 @in = @args;
227 0 shift(@in);
228  
229 ▶ } elsif (lc($args[0]) eq 'exact' ||
Condition100%6/6
lc $args[0] eq "exact" or lc $args[0] eq "approx" or lc $args[0] eq "semi"
l!l&&r!l&&!r
1261
lc $args[0] eq "exact" or lc $args[0] eq "approx"
l!l&&r!l&&!r
667
MC/DC100%3/3
lc $args[0] eq "exact" or lc $args[0] eq "approx" or lc $args[0] eq "semi"
lc $args[0] eq "exact" lc $args[0] eq "approx" lc $args[0] eq "semi"
Truth table100%4/4
A or B or C
A= lc $args[0] eq "exact"B= lc $args[0] eq "approx"C= lc $args[0] eq "semi"
ABCresult
1XX1
01X1
0011
0000
230 lc($args[0]) eq 'approx' ||
231 lc($args[0]) eq 'semi') {
232 18 ($mode,$dec,@in) = (@args);
233 18 $mode = lc($mode);
234  
235 } elsif ($args[0] =~ /^\d+$/) {
236 0 ($mode,$dec,@in) = ('exact',@args);
237  
238 } else {
239 1 $mode = 'exact';
240 1 @in = @args;
241 }
242  
243 19 ▶ $dec = 0 if (! $dec);
Branch: 1 branch
BranchTrueFalseTotal
unless $dec 1 18 19
244 19 @in = _Delta_Format_old($mode,$dec,@in);
245  
246 19 my @ret = ();
247 19 foreach my $in (@in) {
248 19 push(@ret,$delta->printf($in));
249 }
250  
251 19 ▶ if (! wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 0 19 19
252 0 return join(" ",@ret);
253 }
254  
255 19 return @ret;
256 }
257  
258 19 ▶sub _Delta_Format_old {
Subroutine _Delta_Format_old: called CC=36 SCAR=35.8
259 19 my($mode,$dec,@in) = @_;
260 19 my(@ret);
261 19 my $business = $delta->type('business');
262  
263 19 foreach my $in (@in) {
264 19 my $out = '';
265  
266 # This will look for old formats (%Xd, %Xh, %Xt) and turn them
267 # into the new format: %XYZ
268  
269 19 ▶ while ($in) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in) 248 19 267
270 248 ▶ if ($in =~ s/^([^%]+)//) {
Branch: 3 branches
BranchTrueFalseTotal
if ($in =~ s/^([^%]+)//) { } 115 133 248
elsif ($in =~ /^%[yMwdhms][yMwdhms][yMwdhms]/) { } 0 133 133
elsif ($in =~ s/^%([yMwdhms])([dht])//) { } 126 7 133
271 115 $out .= $1;
272  
273 } elsif ($in =~ /^%[yMwdhms][yMwdhms][yMwdhms]/) {
274 # It's one of the new formats so don't modify it.
275 0 $in =~ s/^%//;
276 0 $out .= '%';
277  
278 } elsif ($in =~ s/^%([yMwdhms])([dht])//) {
279 126 my($field,$scope) = ($1,$2);
280 126 $out .= '%';
281  
282 126 ▶ if ($scope eq 'd') {
Branch: 3 branches
BranchTrueFalseTotal
if ($scope eq 'd') { } 42 84 126
elsif ($scope eq 'h') { } 42 42 84
elsif ($scope eq 't') { } 42 0 42
283 42 ▶ if ($mode eq 'approx') {
Branch: 5 branches
BranchTrueFalseTotal
if ($mode eq 'approx') { } 14 28 42
elsif ($field eq 'y' or $field eq 'M') { } 8 20 28
elsif ($mode eq 'semi') { } 10 10 20
elsif ($field eq 'w' and $business) { } 1 9 10
elsif ($field eq 'w' || $field eq 'd' and not $business) { } 2 7 9
284 14 $out .= ".${dec}${field}${field}s";
285 ▶ } elsif ($field eq 'y' || $field eq 'M') {
Condition100%3/3
$field eq "y" or $field eq "M"
l!l&&r!l&&!r
4420
MC/DC100%2/2
$field eq "y" or $field eq "M"
$field eq "y" $field eq "M"
Truth table100%3/3
A or B
A= $field eq "y"B= $field eq "M"
ABresult
1X1
011
000
286 8 $out .= ".${dec}${field}${field}M";
287 } elsif ($mode eq 'semi') {
288 10 $out .= ".${dec}${field}${field}s";
289 ▶ } elsif ($field eq 'w' && $business) {
Condition100%3/3
$field eq "w" and $business
!ll&&!rl&&r
811
MC/DC100%2/2
$field eq "w" and $business
$field eq "w" $business
Truth table100%3/3
A and B
A= $field eq "w"B= $business
ABresult
0X0
100
111
290 1 $out .= ".${dec}www";
291 ▶ } elsif (($field eq 'w' || $field eq 'd') && ! $business) {
Condition100%6/6
$field eq "w" || $field eq "d" and not $business
!ll&&!rl&&r
612
$field eq "w" or $field eq "d"
l!l&&r!l&&!r
126
MC/DC100%3/3
$field eq "w" || $field eq "d" and not $business
$field eq "w" $field eq "d" not $business
Truth table80%4/5
A or B and not(C)
A= $field eq "w"B= $field eq "d"C= not $business
ABCresult
00X0
1X00
0100
1X11
0111
292 2 $out .= ".${dec}${field}${field}d";
293 } else {
294 7 $out .= ".${dec}${field}${field}s";
295 }
296  
297 } elsif ($scope eq 'h') {
298 42 ▶ if ($mode eq 'approx') {
Branch: 6 branches
BranchTrueFalseTotal
if ($mode eq 'approx') { } 14 28 42
elsif ($field eq 'y' or $field eq 'M') { } 8 20 28
elsif ($mode eq 'semi') { } 10 10 20
elsif ($field eq 'w') { } 2 8 10
elsif ($field eq 'd' and not $business) { } 1 7 8
elsif ($business) { } 4 3 7
299 14 $out .= ".${dec}${field}y${field}";
300 ▶ } elsif ($field eq 'y' || $field eq 'M') {
Condition100%3/3
$field eq "y" or $field eq "M"
l!l&&r!l&&!r
4420
MC/DC100%2/2
$field eq "y" or $field eq "M"
$field eq "y" $field eq "M"
Truth table100%3/3
A or B
A= $field eq "y"B= $field eq "M"
ABresult
1X1
011
000
301 8 $out .= ".${dec}${field}y${field}";
302 } elsif ($mode eq 'semi') {
303 10 $out .= ".${dec}${field}w${field}";
304 } elsif ($field eq 'w') {
305 2 $out .= ".${dec}www";
306 ▶ } elsif ($field eq 'd' && ! $business) {
Condition100%3/3
$field eq "d" and not $business
!ll&&!rl&&r
611
MC/DC100%2/2
$field eq "d" and not $business
$field eq "d" not $business
Truth table100%3/3
A and not(B)
A= $field eq "d"B= not $business
ABresult
0X0
100
111
307 1 $out .= ".${dec}dwd";
308 } elsif ($business) {
309 4 $out .= ".${dec}${field}d${field}";
310 } else {
311 3 $out .= ".${dec}${field}h${field}";
312 }
313  
314 } elsif ($scope eq 't') {
315 42 ▶ if ($mode eq 'approx') {
Branch: 6 branches
BranchTrueFalseTotal
if ($mode eq 'approx') { } 14 28 42
elsif ($field eq 'y' or $field eq 'M') { } 8 20 28
elsif ($mode eq 'semi') { } 10 10 20
elsif ($field eq 'w' and $business) { } 1 9 10
elsif ($field eq 'w' || $field eq 'd' and not $business) { } 2 7 9
elsif ($business) { } 4 3 7
316 14 $out .= ".${dec}${field}ys";
317 ▶ } elsif ($field eq 'y' || $field eq 'M') {
Condition100%3/3
$field eq "y" or $field eq "M"
l!l&&r!l&&!r
4420
MC/DC100%2/2
$field eq "y" or $field eq "M"
$field eq "y" $field eq "M"
Truth table100%3/3
A or B
A= $field eq "y"B= $field eq "M"
ABresult
1X1
011
000
318 8 $out .= ".${dec}${field}yM";
319 } elsif ($mode eq 'semi') {
320 10 $out .= ".${dec}${field}ws";
321 ▶ } elsif ($field eq 'w' && $business) {
Condition100%3/3
$field eq "w" and $business
!ll&&!rl&&r
811
MC/DC100%2/2
$field eq "w" and $business
$field eq "w" $business
Truth table100%3/3
A and B
A= $field eq "w"B= $business
ABresult
0X0
100
111
322 1 $out .= ".${dec}www";
323 ▶ } elsif (($field eq 'w' || $field eq 'd') && ! $business) {
Condition100%6/6
$field eq "w" || $field eq "d" and not $business
!ll&&!rl&&r
612
$field eq "w" or $field eq "d"
l!l&&r!l&&!r
126
MC/DC100%3/3
$field eq "w" || $field eq "d" and not $business
$field eq "w" $field eq "d" not $business
Truth table80%4/5
A or B and not(C)
A= $field eq "w"B= $field eq "d"C= not $business
ABCresult
00X0
1X00
0100
1X11
0111
324 2 $out .= ".${dec}${field}wd";
325 } elsif ($business) {
326 4 $out .= ".${dec}${field}ds";
327 } else {
328 3 $out .= ".${dec}${field}hs";
329 }
330 }
331  
332 } else {
333 # It's one of the new formats so don't modify it.
334 7 $in =~ s/^%//;
335 7 $out .= '%';
336 }
337 }
338  
339 19 push(@ret,$out);
340 }
341  
342 19 return @ret;
343 }
344  
345 120 ▶sub DateCalc {
Subroutine DateCalc: called CC=37 SCAR=60.0
Pod documented
346 120 my($d1,$d2,@args) = @_;
347  
348 # Handle \$err arg
349  
350 120 my($ref,$errref);
351  
352 120 ▶ if (@args && ref($args[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args and ref $args[0]) { } 0 120 120
Condition66%2/3
@args and ref $args[0]
!ll&&!rl&&r
60600
MC/DC0%0/2
@args and ref $args[0]
@args ref $args[0]
Truth table66%2/3
A and B
A= @argsB= ref $args[0]
ABresult
0X0
100
111
353 0 $errref = shift(@args);
354 0 $ref = 1;
355 } else {
356 120 $ref = 0;
357 }
358  
359 # Parse $d1 and $d2
360  
361 120 my ($obj1,$obj2,$err,$usemode);
362 120 $usemode = 1;
363  
364 120 $obj1 = $date->new_date();
365 120 $err = $obj1->parse($d1,'nodelta');
366 120 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 120 120
367 0 $obj1 = $date->new_delta();
368 0 $err = $obj1->parse($d1);
369 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
370 0 ▶ $$errref = 1 if ($ref);
Branch: 1 branch
BranchTrueFalseTotal
if $ref 0 0 0
371 0 return '';
372 }
373 0 $usemode = 0;
374 }
375  
376 120 $obj2 = $date->new_date();
377 120 $err = $obj2->parse($d2,'nodelta');
378 120 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 49 71 120
379 49 $obj2 = $date->new_delta();
380 49 $err = $obj2->parse($d2);
381 49 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 49 49
382 0 ▶ $$errref = 2 if ($ref);
Branch: 1 branch
BranchTrueFalseTotal
if $ref 0 0 0
383 0 return '';
384 }
385 49 $usemode = 0;
386 }
387  
388 # Handle $mode
389  
390 120 my($mode);
391 120 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 60 60 120
392 60 $mode = shift(@args);
393 }
394 120 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 120 120
395 0 ▶ $$errref = 3 if ($ref);
Branch: 1 branch
BranchTrueFalseTotal
if $ref 0 0 0
396 0 return '';
397 }
398  
399 # Apply the $mode to any deltas
400  
401 120 ▶ if (defined($mode)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mode) 60 60 120
402 60 ▶ if (ref($obj1) eq 'Date::Manip::Delta') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj1 eq "Date::Manip::Delta") 0 60 60
403 0 ▶ if ($$obj1{'data'}{'gotmode'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj1->{'data'}{'gotmode'}) { } 0 0 0
404 0 ▶ if ($mode == 2 || $mode == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode == 2 or $mode == 3) { } 0 0 0
Condition0%0/3
$mode == 2 or $mode == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
$mode == 2 or $mode == 3
$mode == 2 $mode == 3
Truth table0%0/3
A or B
A= $mode == 2B= $mode == 3
ABresult
1X1
011
000
405 0 ▶ if (! $obj1->type('business')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj1->type("business")) 0 0 0
406 0 ▶ $$errref = 3 if ($ref);
Branch: 1 branch
BranchTrueFalseTotal
if $ref 0 0 0
407 0 return '';
408 }
409 } else {
410 0 ▶ if ($obj1->type('business')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj1->type("business")) 0 0 0
411 0 ▶ $$errref = 3 if ($ref);
Branch: 1 branch
BranchTrueFalseTotal
if $ref 0 0 0
412 0 return '';
413 }
414 }
415 } else {
416 0 ▶ if ($mode == 2 || $mode == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode == 2 or $mode == 3) { } 0 0 0
Condition0%0/3
$mode == 2 or $mode == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
$mode == 2 or $mode == 3
$mode == 2 $mode == 3
Truth table0%0/3
A or B
A= $mode == 2B= $mode == 3
ABresult
1X1
011
000
417 0 $obj1->set('mode','business');
418 } else {
419 0 $obj1->set('mode','normal');
420 }
421 }
422 }
423  
424 60 ▶ if (ref($obj2) eq 'Date::Manip::Delta') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj2 eq "Date::Manip::Delta") 0 60 60
425 0 ▶ if ($$obj2{'data'}{'gotmode'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj2->{'data'}{'gotmode'}) { } 0 0 0
426 0 ▶ if ($mode == 2 || $mode == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode == 2 or $mode == 3) { } 0 0 0
Condition0%0/3
$mode == 2 or $mode == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
$mode == 2 or $mode == 3
$mode == 2 $mode == 3
Truth table0%0/3
A or B
A= $mode == 2B= $mode == 3
ABresult
1X1
011
000
427 0 ▶ if (! $obj2->type('business')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj2->type("business")) 0 0 0
428 0 ▶ $$errref = 3 if ($ref);
Branch: 1 branch
BranchTrueFalseTotal
if $ref 0 0 0
429 0 return '';
430 }
431 } else {
432 0 ▶ if ($obj2->type('business')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj2->type("business")) 0 0 0
433 0 ▶ $$errref = 3 if ($ref);
Branch: 1 branch
BranchTrueFalseTotal
if $ref 0 0 0
434 0 return '';
435 }
436 }
437 } else {
438 0 ▶ if ($mode ==2 || $mode == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode == 2 or $mode == 3) { } 0 0 0
Condition0%0/3
$mode == 2 or $mode == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
$mode == 2 or $mode == 3
$mode == 2 $mode == 3
Truth table0%0/3
A or B
A= $mode == 2B= $mode == 3
ABresult
1X1
011
000
439 0 $obj2->set('mode','business');
440 } else {
441 0 $obj2->set('mode','normal');
442 }
443 }
444 }
445 }
446  
447 # Do the calculation
448  
449 120 my $obj3;
450 120 ▶ if ($usemode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($usemode) { } 71 49 120
451 71 ▶ $mode = 'exact' if (! $mode);
Branch: 1 branch
BranchTrueFalseTotal
unless $mode 11 60 71
452 71 my %tmp = ('0' => 'exact',
453 '1' => 'approx',
454 '2' => 'bapprox',
455 '3' => 'business',
456 'exact' => 'exact',
457 'semi' => 'semi',
458 'approx' => 'approx',
459 'business'=> 'business',
460 'bsemi' => 'bsemi',
461 'bapprox' => 'bapprox',
462 );
463  
464 71 ▶ if (exists $tmp{$mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tmp{$mode}) { } 71 0 71
465 71 $mode = $tmp{$mode};
466 } else {
467 0 ▶ $$errref = 3 if ($ref);
Branch: 1 branch
BranchTrueFalseTotal
if $ref 0 0 0
468 0 return '';
469 }
470  
471 71 $obj3 = $obj1->calc($obj2,$mode);
472 } else {
473 49 $obj3 = $obj1->calc($obj2);
474 }
475  
476 120 my $ret = $obj3->value();
477 120 return $ret;
478 }
479  
480 34 ▶sub Date_GetPrev {
Subroutine Date_GetPrev: called CC=9 SCAR=22.2
Pod documented
481 34 my($string,$dow,$curr,@time) = @_;
482 34 my $err = $date->parse($string);
483 34 ▶ return '' if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 34 34
484  
485 34 ▶ if (defined($dow)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dow) 11 23 34
486 11 $dow = lc($dow);
487 11 ▶ if (exists $$dmb{'data'}{'wordmatch'}{'day_char'}{$dow}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $Date::Manip::DM6::dmb->{'data'}{'wordmatch'}{'day_char'}{$dow}) { } 0 11 11
elsif (exists $Date::Manip::DM6::dmb->{'data'}{'wordmatch'}{'day_abb'}{$dow}) { } 10 1 11
elsif (exists $Date::Manip::DM6::dmb->{'data'}{'wordmatch'}{'day_name'}{$dow}) { } 0 1 1
488 0 $dow = $$dmb{'data'}{'wordmatch'}{'day_char'}{$dow};
489 } elsif (exists $$dmb{'data'}{'wordmatch'}{'day_abb'}{$dow}) {
490 10 $dow = $$dmb{'data'}{'wordmatch'}{'day_abb'}{$dow};
491 } elsif (exists $$dmb{'data'}{'wordmatch'}{'day_name'}{$dow}) {
492 0 $dow = $$dmb{'data'}{'wordmatch'}{'day_name'}{$dow};
493 }
494 }
495  
496 34 ▶ if ($#time == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#time == 0) 7 27 34
497 7 @time = @{ $dmb->split('hms',$time[0]) };
498 }
499  
500 34 ▶ if (@time) {
Branch: 1 branch
BranchTrueFalseTotal
if (@time) { } 29 5 34
501 29 ▶ while ($#time < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#time < 2) 7 29 36
502 7 push(@time,0);
503 }
504 29 $date->prev($dow,$curr,\@time);
505 } else {
506 5 $date->prev($dow,$curr);
507 }
508 34 my $ret = $date->value();
509 34 return $ret;
510 }
511  
512 34 ▶sub Date_GetNext {
Subroutine Date_GetNext: called CC=9 SCAR=22.2
Pod documented
513 34 my($string,$dow,$curr,@time) = @_;
514 34 my $err = $date->parse($string);
515 34 ▶ return '' if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 34 34
516  
517 34 ▶ if (defined($dow)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dow) 11 23 34
518 11 $dow = lc($dow);
519 11 ▶ if (exists $$dmb{'data'}{'wordmatch'}{'day_char'}{$dow}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $Date::Manip::DM6::dmb->{'data'}{'wordmatch'}{'day_char'}{$dow}) { } 0 11 11
elsif (exists $Date::Manip::DM6::dmb->{'data'}{'wordmatch'}{'day_abb'}{$dow}) { } 10 1 11
elsif (exists $Date::Manip::DM6::dmb->{'data'}{'wordmatch'}{'day_name'}{$dow}) { } 0 1 1
520 0 $dow = $$dmb{'data'}{'wordmatch'}{'day_char'}{$dow};
521 } elsif (exists $$dmb{'data'}{'wordmatch'}{'day_abb'}{$dow}) {
522 10 $dow = $$dmb{'data'}{'wordmatch'}{'day_abb'}{$dow};
523 } elsif (exists $$dmb{'data'}{'wordmatch'}{'day_name'}{$dow}) {
524 0 $dow = $$dmb{'data'}{'wordmatch'}{'day_name'}{$dow};
525 }
526 }
527  
528 34 ▶ if ($#time == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#time == 0) 7 27 34
529 7 @time = @{ $dmb->split('hms',$time[0]) };
530 }
531  
532 34 ▶ if (@time) {
Branch: 1 branch
BranchTrueFalseTotal
if (@time) { } 29 5 34
533 29 ▶ while ($#time < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#time < 2) 7 29 36
534 7 push(@time,0);
535 }
536 29 $date->next($dow,$curr,\@time);
537 } else {
538 5 $date->next($dow,$curr);
539 }
540 34 my $ret = $date->value();
541 34 return $ret;
542 }
543  
544 5 ▶sub Date_SetTime {
Subroutine Date_SetTime: called CC=4 SCAR=13.9
Pod documented
545 5 my($string,@time) = @_;
546  
547 5 my $err = $date->parse($string);
548 5 ▶ return '' if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 5 5
549  
550 5 ▶ if ($#time == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#time == 0) 3 2 5
551 3 @time = @{ $dmb->split('hms',$time[0]) };
552 }
553  
554 5 ▶ while ($#time < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#time < 2) 1 5 6
555 1 push(@time,0);
556 }
557  
558 5 $date->set('time',\@time);
559 5 my $val = $date->value();
560 5 return $val;
561 }
562  
563 0 ▶sub Date_SetDateField {
Subroutine Date_SetDateField: not called CC=2 SCAR=17.9
Pod documented
564 0 my($string,$field,$val) = @_;
565  
566 0 my $err = $date->parse($string);
567 0 ▶ return '' if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
568  
569 0 $date->set($field,$val);
570 0 my $ret = $date->value();
571 0 return $ret;
572 }
573  
574 0 ▶sub Date_NextWorkDay {
Subroutine Date_NextWorkDay: not called CC=2 SCAR=17.9
Pod documented
575 0 my($string,$n,$checktime) = @_;
576 0 my $err = $date->parse($string);
577 0 ▶ return '' if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
578 0 $date->next_business_day($n,$checktime);
579 0 my $val = $date->value();
580 0 return $val;
581 }
582  
583 0 ▶sub Date_PrevWorkDay {
Subroutine Date_PrevWorkDay: not called CC=2 SCAR=17.9
Pod documented
584 0 my($string,$n,$checktime) = @_;
585 0 my $err = $date->parse($string);
586 0 ▶ return '' if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
587 0 $date->prev_business_day($n,$checktime);
588 0 my $val = $date->value();
589 0 return $val;
590 }
591  
592 0 ▶sub Date_NearestWorkDay {
Subroutine Date_NearestWorkDay: not called CC=2 SCAR=17.9
Pod documented
593 0 my($string,$tomorrowfirst) = @_;
594 0 my $err = $date->parse($string);
595 0 ▶ return '' if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
596 0 $date->nearest_business_day($tomorrowfirst);
597 0 my $val = $date->value();
598 0 return $val;
599 }
600  
601 93 ▶sub ParseRecur {
Subroutine ParseRecur: called CC=12 SCAR=43.2
Pod documented
602 93 my($string,@args) = @_;
603  
604 93 ▶ if ($#args == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#args == 3) 0 93 93
605 0 my($base,$d0,$d1,$flags) = @args;
606 0 @args = ();
607 0 ▶ push(@args,$flags) if ($flags);
Branch: 1 branch
BranchTrueFalseTotal
if $flags 0 0 0
608 0 push(@args,$base,$d0,$d1);
609 }
610  
611 93 my $err = $recur->parse($string,@args);
612 93 ▶ return '' if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 93 93
613  
614 93 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 93 0 93
615 93 my @dates = $recur->dates();
616 93 my @ret;
617 93 foreach my $d (@dates) {
618 363 my $val = $d->value();
619 363 push(@ret,$val);
620 }
621 93 return @ret;
622 }
623  
624 0 my @int = @{ $$recur{'data'}{'interval'} };
625 0 my @rtime = @{ $$recur{'data'}{'rtime'} };
626 0 my @flags = @{ $$recur{'data'}{'flags'} };
627 0 my $start = $$recur{'data'}{'start'};
628 0 my $end = $$recur{'data'}{'end'};
629 0 my $base = $$recur{'data'}{'base'};
630  
631 0 my $r;
632 0 ▶ if (@int) {
Branch: 1 branch
BranchTrueFalseTotal
if (@int) 0 0 0
633 0 $r = join(':',@int);
634 }
635 0 ▶ if (@rtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rtime) 0 0 0
636 0 my @rt;
637 0 foreach my $rt (@rtime) {
638 0 push(@rt,join(",",@$rt));
639 }
640 0 $r .= '*' . join(':',@rt);
641 }
642  
643 0 $r .= '*' . join(",",@flags);
644  
645 0 ▶ my $val = (defined($base) ? $base->value() : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $base ? : 0 0 0
646 0 $r .= "*$val";
647  
648 0 ▶ $val = (defined($start) ? $start->value() : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $start ? : 0 0 0
649 0 $r .= "*$val";
650  
651 0 ▶ $val = (defined($end) ? $end->value() : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $end ? : 0 0 0
652 0 $r .= "*$val";
653  
654 0 return $r;
655 }
656  
657 8 ▶sub Events_List {
Subroutine Events_List: called CC=18 SCAR=29.3
Pod documented
658 8 my($datestr,@args) = @_;
659  
660 # First argument is always a date
661  
662 8 my $err = $date->parse($datestr);
663 8 ▶ return [] if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 8 8
664  
665 # Second argument is absent, a date, or 0.
666  
667 8 my @list;
668 8 my $flag = 0;
669 8 my ($date0,$date1);
670  
671 8 ▶ if (! @args) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @args) { } 4 4 8
672 # absent
673 4 @list = $date->list_events('dates');
674  
675 } else {
676 # a date or 0
677 4 my $arg = shift(@args);
678 4 ▶ $flag = shift(@args) if (@args);
Branch: 1 branch
BranchTrueFalseTotal
if @args 2 2 4
679 4 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 4 4
680 0 carp "ERROR: unknown argument list";
681 0 return [];
682 }
683  
684 4 ▶ if (! $arg) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $arg) { } 1 3 4
685 1 my($y,$m,$d) = $date->value();
686 1 $date2->set('date',[$y,$m,$d,23,59,59]);
687 1 @list = $date->list_events(0, 'dates');
688  
689 } else {
690 3 $err = $date2->parse($arg);
691 3 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 3 3
692 0 carp "ERROR: invalid argument: $arg";
693 0 return [];
694 }
695 3 @list = $date->list_events($date2, 'dates');
696 }
697 }
698  
699 # Handle the flag
700  
701 8 ▶ if (! $flag) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($flag) 6 2 8
702 6 my @ret = ();
703 6 foreach my $e (@list) {
704 11 my($d,@n) = @$e;
705 11 my $v = $d->value();
706 11 push(@ret,$v,[@n]);
707 }
708 6 return \@ret;
709 }
710  
711 2 push(@list,[$date2]);
712 2 my %ret;
713  
714 2 ▶ if ($flag==1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($flag == 1) { } 1 1 2
elsif ($flag == 2) { } 1 0 1
715 1 ▶ while ($#list > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#list > 0) 4 1 5
716 4 my($d0,@n) = @{ shift(@list) };
717 4 my $d1 = $list[0]->[0];
718 4 my $delta = $d0->calc($d1);
719  
720 4 foreach $flag (@n) {
721 5 ▶ $flag = '' if (! defined($flag));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flag 0 5 5
722 5 ▶ if (exists $ret{$flag}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ret{$flag}) { } 2 3 5
723 2 $ret{$flag} = $ret{$flag}->calc($delta);
724 } else {
725 3 $ret{$flag} = $delta;
726 }
727 }
728 }
729  
730 } elsif ($flag==2) {
731 1 ▶ while ($#list > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#list > 0) 4 1 5
732 4 my($d0,@n) = @{ shift(@list) };
733 4 my $d1 = $list[0]->[0];
734 4 my $delta = $d0->calc($d1);
735 4 $flag = join("+",sort(@n));
736  
737 4 ▶ if (exists $ret{$flag}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ret{$flag}) { } 1 3 4
738 1 $ret{$flag} = $ret{$flag}->calc($delta);
739 } else {
740 3 $ret{$flag} = $delta;
741 }
742 }
743  
744 } else {
745 0 carp "ERROR: Invalid flag $flag";
746 0 return [];
747 }
748  
749 2 foreach my $flag (keys %ret) {
750 6 $ret{$flag} = $ret{$flag}->value();
751 }
752  
753 2 return \%ret;
754 }
755  
756 ########################################################################
757 # ADDITIONAL ROUTINES
758 ########################################################################
759  
760 0 ▶sub Date_DayOfWeek {
Subroutine Date_DayOfWeek: not called CC=1 SCAR=6.9
Pod documented
761 0 my($m,$d,$y) = @_;
762 0 return $dmb->day_of_week([$y,$m,$d]);
763 }
764  
765 0 ▶sub Date_SecsSince1970 {
Subroutine Date_SecsSince1970: not called CC=1 SCAR=6.9
Pod documented
766 0 my($m,$d,$y,$h,$mn,$s) = @_;
767 0 return $dmb->secs_since_1970([$y,$m,$d,$h,$mn,$s]);
768 }
769  
770 0 ▶sub Date_SecsSince1970GMT {
Subroutine Date_SecsSince1970GMT: not called CC=1 SCAR=6.9
Pod documented
771 0 my($m,$d,$y,$h,$mn,$s) = @_;
772 0 $date->set('date',[$y,$m,$d,$h,$mn,$s]);
773 0 return $date->secs_since_1970_GMT();
774 }
775  
776 0 ▶sub Date_DaysSince1BC {
Subroutine Date_DaysSince1BC: not called CC=1 SCAR=6.9
Pod documented
777 0 my($m,$d,$y) = @_;
778 0 return $dmb->days_since_1BC([$y,$m,$d]);
779 }
780  
781 0 ▶sub Date_DayOfYear {
Subroutine Date_DayOfYear: not called CC=1 SCAR=6.9
Pod documented
782 0 my($m,$d,$y) = @_;
783 0 return $dmb->day_of_year([$y,$m,$d]);
784 }
785  
786 7 ▶sub Date_NthDayOfYear {
Subroutine Date_NthDayOfYear: called CC=2 SCAR=6.9
Pod documented
787 7 my($y,$n) = @_;
788 7 my @ret = @{ $dmb->day_of_year($y,$n) };
789 7 ▶ push(@ret,0,0,0) if ($#ret == 2);
Branch: 1 branch
BranchTrueFalseTotal
if $#ret == 2 3 4 7
790 7 return @ret;
791 }
792  
793 0 ▶sub Date_DaysInMonth {
Subroutine Date_DaysInMonth: not called CC=1 SCAR=6.9
Pod documented
794 0 my($m,$y) = @_;
795 0 return $dmb->days_in_month($y,$m);
796 }
797  
798 0 ▶sub Date_DaysInYear {
Subroutine Date_DaysInYear: not called CC=1 SCAR=6.9
Pod documented
799 0 my($y) = @_;
800 0 return $dmb->days_in_year($y);
801 }
802  
803 0 ▶sub Date_WeekOfYear {
Subroutine Date_WeekOfYear: not called CC=3 SCAR=24.8
Pod documented
804 0 my($m,$d,$y,$first) = @_;
805 0 my $currfirst = $dmb->_config('firstday');
806 0 $dmb->config('firstday',$first);
807 0 my($yy,$ww) = $dmb->week_of_year([$y,$m,$d]);
808 0 $dmb->config('firstday',$currfirst);
809 0 ▶ return 0 if ($yy<$y);
Branch: 1 branch
BranchTrueFalseTotal
if $yy < $y 0 0 0
810 0 ▶ return 53 if ($yy>$y);
Branch: 1 branch
BranchTrueFalseTotal
if $yy > $y 0 0 0
811 0 return $ww;
812 }
813  
814 0 ▶sub Date_LeapYear {
Subroutine Date_LeapYear: not called CC=1 SCAR=6.9
Pod documented
815 0 my($y) = @_;
816 0 return $dmb->leapyear($y);
817 }
818  
819 0 ▶sub Date_DaySuffix {
Subroutine Date_DaySuffix: not called CC=1 SCAR=6.9
Pod documented
820 0 my($d) = @_;
821 0 return $$dmb{'data'}{'wordlist'}{'nth_dom'}[$d-1];
822 }
823  
824 0 ▶sub Date_TimeZone {
Subroutine Date_TimeZone: not called CC=1 SCAR=6.9
Pod documented
825 0 my($ret) = $dmb->_now('tz');
826 0 return $ret;
827 }
828  
829 14 ▶sub Date_ConvTZ {
Subroutine Date_ConvTZ: called CC=10 SCAR=25.1
Pod documented
830 14 my($str,$from,$to) = @_;
831 14 ▶ $from = $dmb->_now('tz') if (! $from);
Branch: 1 branch
BranchTrueFalseTotal
unless $from 0 14 14
832 14 ▶ $to = $dmb->_now('tz') if (! $to);
Branch: 1 branch
BranchTrueFalseTotal
unless $to 0 14 14
833  
834 # Parse the date (ignoring timezone information):
835  
836 14 my $err = $dateUT->parse($str);
837 14 ▶ return '' if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 14 14
838 14 my $d = [ $dateUT->value() ];
839 14 ▶ return '' if (! $d);
Branch: 1 branch
BranchTrueFalseTotal
unless $d 0 14 14
840  
841 # Get the timezone for $from. First, we'll assume that
842 # the date matches exactly (so if the timezone is passed
843 # in as an abbreviation, we'll try to get the timezone
844 # that fits the date/abbrev combination). If we can't,
845 # we'll just assume that the timezone is more generic
846 # and try it without the date.
847  
848 14 my $tmp;
849 14 $tmp = $dmt->zone($from,$d);
850 14 ▶ if (! $tmp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp) 0 14 14
851 0 $tmp = $dmt->zone($from);
852 0 ▶ return '' if (! $tmp);
Branch: 1 branch
BranchTrueFalseTotal
unless $tmp 0 0 0
853 }
854 14 $from = $tmp;
855  
856 14 $tmp = $dmt->zone($to,$d);
857 14 ▶ if (! $tmp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmp) 2 12 14
858 2 $tmp = $dmt->zone($to);
859 2 ▶ return '' if (! $tmp);
Branch: 1 branch
BranchTrueFalseTotal
unless $tmp 0 2 2
860 }
861 14 $to = $tmp;
862  
863 14 ($err,$d) = $dmt->convert($d,$from,$to);
864 14 ▶ return '' if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 14 14
865 14 return $dmb->join('date',$d);
866 }
867  
868 0 ▶sub Date_IsWorkDay {
Subroutine Date_IsWorkDay: not called CC=2 SCAR=17.9
Pod documented
869 0 my($str,$checktime) = @_;
870 0 my $err = $date->parse($str);
871 0 ▶ return '' if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
872 0 return $date->is_business_day($checktime);
873 }
874  
875 2 ▶sub Date_IsHoliday {
Subroutine Date_IsHoliday: called CC=3 SCAR=11.0
Pod documented
876 2 my($str) = @_;
877 2 my $err = $date->parse($str);
878 2 ▶ return undef if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 2 2
879 2 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 1 1 2
880 1 my @ret = $date->holiday();
881 1 return @ret;
882 } else {
883 1 my $ret = $date->holiday();
884 1 return $ret;
885 }
886 }
887  
888 0 ▶sub Date_Cmp {
Subroutine Date_Cmp: not called CC=3 SCAR=24.8
Pod documented
889 0 my($str1,$str2) = @_;
890 0 my $err = $date->parse($str1);
891 0 ▶ return undef if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
892 0 $err = $date2->parse($str2);
893 0 ▶ return undef if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
894 0 return $date->cmp($date2);
895 }
896  
897 170 1;
898 # Local Variables:
899 # mode: cperl
900 # indent-tabs-mode: nil
901 # cperl-indent-level: 3
902 # cperl-continued-statement-offset: 2
903 # cperl-continued-brace-offset: 0
904 # cperl-brace-offset: 0
905 # cperl-brace-imaginary-offset: 0
906 # cperl-label-offset: 0
907 # End:
« lib/Date/Manip/Recur.pm ↑ Summary lib/Date/Manip/Delta.pm »