DateUtil.pm

filter: Statementstmt 84.4% 326 / 386 Branchbran 68.3% 216 / 316 Conditioncond 44.8% 152 / 339 MC/DCmcdc 20.8% 36 / 173 Subroutinesub 86.4% 51 / 59 Podpod 94.0% 47 / 50 totaltotal 62.5% 828 / 1323 CC 273 SCAR 28.0
CC
273
Cov
67%
skipOnDate
47.4
convertDateFromMMM
42.0
convertDateToMMM
30.0
CRAP 16.5
« Common.pm ↑ Summary checkLogExist.pl »
1 package EAI::DateUtil 1.921;
2  
3 6 ▶use strict; use warnings; use feature 'unicode_strings'; use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Exporter qw(import); use Time::Local qw( timelocal_modern timegm_modern ); use Time::localtime; use POSIX qw(mktime); use Carp qw(cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 our @EXPORT = qw(monthsToInt intToMonths addLocaleMonths get_curdate get_curdatetime get_curdate_dot formatDate formatDateFromYYYYMMDD get_curdate_dash get_curdate_gen get_curdate_dash_plus_X_years get_curtime get_curtime_HHMM get_lastdateYYYYMMDD get_lastdateDDMMYYYY is_first_day_of_month is_last_day_of_month get_last_day_of_month weekday is_weekend is_holiday is_easter addCalendar first_week first_weekYYYYMMDD last_week last_weekYYYYMMDD convertDate convertDateFromMMM convertDateToMMM convertToDDMMYYYY addDays addDaysHol addDatePart subtractDays subtractDaysHol convertcomma convertToThousendDecimal get_dateseries parseFromDDMMYYYY parseFromYYYYMMDD convertEpochToYYYYMMDD convertJulianToYYYYMMDD make_time formatTime get_curtime_epochs localtime timelocal_modern skipOnDate);
7  
8 6 my %monthsToInt = (
9 "en" => {"jan" => "01","feb" => "02","mar" => "03","apr" => "04","may" => "05","jun" => "06","jul" => "07","aug" => "08","sep" => "09","oct" => "10","nov" => "11","dec" => "12"},
10 "ge" => {"jan" => "01","feb" => "02","mär" => "03","apr" => "04","mai" => "05","jun" => "06","jul" => "07","aug" => "08","sep" => "09","okt" => "10","nov" => "11","dez" => "12"}
11 );
12 6 my %intTomonths = (
13 "en" => ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
14 "ge" => ["Jan","Feb","Mär","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"]
15 );
16  
17 4 ▶sub monthsToInt ($$) {
Subroutine monthsToInt: called CC=5 SCAR=20.2
Pod documented
18 4 my ($m,$locale) = @_;
19 4 ▶ return undef if !$m or !$locale;
Branch: 1 branch
BranchTrueFalseTotal
unless $m and $locale 0 4 4
Condition33%1/3
$m and $locale
!ll&&!rl&&r
004
MC/DC0%0/2
$m and $locale
$m $locale
Truth table33%1/3
A and B
A= $mB= $locale
ABresult
0X0
100
111
20 4 ▶ if ($intTomonths{lc($locale)} and defined($monthsToInt{lc($locale)}{$m})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($intTomonths{lc $locale} and defined $monthsToInt{lc $locale}{$m}) { } 4 0 4
Condition33%1/3
$intTomonths{lc $locale} and defined $monthsToInt{lc $locale}{$m}
!ll&&!rl&&r
004
MC/DC0%0/2
$intTomonths{lc $locale} and defined $monthsToInt{lc $locale}{$m}
$intTomonths{lc $locale} defined $monthsToInt{lc $locale}{$m}
Truth table33%1/3
A and B
A= $intTomonths{lc $locale}B= defined $monthsToInt{lc $locale}{$m}
ABresult
0X0
100
111
21 4 return $monthsToInt{lc($locale)}{$m};
22 } else {
23 0 return "";
24 }
25 }
26  
27 9 ▶sub intToMonths ($$) {
Subroutine intToMonths: called CC=5 SCAR=19.6
Pod documented
28 9 my ($m,$locale) = @_;
29 9 ▶ return undef if !$m or !$locale;
Branch: 1 branch
BranchTrueFalseTotal
unless $m and $locale 0 9 9
Condition33%1/3
$m and $locale
!ll&&!rl&&r
009
MC/DC0%0/2
$m and $locale
$m $locale
Truth table33%1/3
A and B
A= $mB= $locale
ABresult
0X0
100
111
30 9 ▶ if ($intTomonths{lc($locale)} and @{$intTomonths{lc($locale)}} >= $m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($intTomonths{lc $locale} and @{$intTomonths{lc $locale};} >= $m) { } 9 0 9
Condition33%1/3
$intTomonths{lc $locale} and @{$intTomonths{lc $locale};} >= $m
!ll&&!rl&&r
009
MC/DC0%0/2
$intTomonths{lc $locale} and @{$intTomonths{lc $locale};} >= $m
$intTomonths{lc $locale} @{$intTomonths{lc $locale};} >= $m
Truth table33%1/3
A and B
A= $intTomonths{lc $locale}B= @{$intTomonths{lc $locale};} >= $m
ABresult
0X0
100
111
31 9 return $intTomonths{lc($locale)}[$m-1];
32 } else {
33 0 return "";
34 }
35 }
36  
37 3 ▶sub get_curdate {
Subroutine get_curdate: called CC=1 SCAR=0.0
Pod documented
38 3 return sprintf("%04d%02d%02d",localtime->year()+ 1900, localtime->mon()+1, localtime->mday());
39 }
40  
41 1 ▶sub get_curdatetime {
Subroutine get_curdatetime: called CC=1 SCAR=0.0
Pod documented
42 1 return sprintf("%04d%02d%02d_%02d%02d%02d",localtime->year()+1900,localtime->mon()+1,localtime->mday(),localtime->hour(),localtime->min(),localtime->sec());
43 }
44  
45 1 ▶sub get_curdate_dot {
Subroutine get_curdate_dot: called CC=1 SCAR=0.0
Pod documented
46 1 return sprintf("%02d.%02d.%04d",localtime->mday(), localtime->mon()+1, localtime->year()+ 1900);
47 }
48  
49 1 ▶sub addLocaleMonths ($$) {
Subroutine addLocaleMonths: called CC=6 SCAR=20.7
Pod documented
50 1 my ($locale,$monthList) = @_;
51 1 ▶ return undef if !$locale or !$monthList;
Branch: 1 branch
BranchTrueFalseTotal
unless $locale and $monthList 0 1 1
Condition33%1/3
$locale and $monthList
!ll&&!rl&&r
001
MC/DC0%0/2
$locale and $monthList
$locale $monthList
Truth table33%1/3
A and B
A= $localeB= $monthList
ABresult
0X0
100
111
52 1 $locale = lc($locale);
53 1 ▶ if (defined($monthsToInt{$locale})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $monthsToInt{$locale}) 0 1 1
54 0 cluck("locale <$locale> already implemented for monthsToInt !");
55 0 return 0;
56 }
57 1 ▶ if (defined($intTomonths{$locale})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $intTomonths{$locale}) 0 1 1
58 0 cluck("locale <$locale> already implemented for intTomonths !");
59 0 return 0;
60 }
61 1 $intTomonths{$locale} = $monthList;
62 1 my $i = 1;
63 1 for (@$monthList) {
64 12 $monthsToInt{$locale}{lc($_)} = sprintf("%02d", $i);
65 12 $i++;
66 }
67 1 return 1;
68 }
69  
70 53 ▶sub formatDate ($$$;$) {
Subroutine formatDate: called CC=10 SCAR=23.2
Pod documented
71 53 my ($y,$m,$d,$template) = @_;
72 53 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 0 53 53
Condition33%2/6
$y and $m and $d
!ll&&!rl&&r
0053
$y and $m
!ll&&!rl&&r
0053
MC/DC0%0/3
$y and $m and $d
$y $m $d
Truth table25%1/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
73 53 ▶ $template = "YMD" if !$template;
Branch: 1 branch
BranchTrueFalseTotal
unless $template 16 37 53
74 53 my ($locale) = $template =~ /\[(.*?)\]$/;
75 53 my $result = $template;
76 53 ▶ $result =~ s/\[$locale\]// if $locale;
Branch: 1 branch
BranchTrueFalseTotal
if $locale 1 52 53
77 53 $y = sprintf("%04d", $y);
78 53 $m = sprintf("%02d", $m);
79 53 $d = sprintf("%02d", $d);
80 53 ▶ if ($result =~ /MMM/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result =~ /MMM/iu) { } 7 46 53
81 7 ▶ $locale = "ge" if $result =~ /mmm/ and !$locale;
Branch: 1 branch
BranchTrueFalseTotal
if $result =~ /mmm/u and not $locale 3 4 7
Condition100%3/3
$result =~ /mmm/u and not $locale
!ll&&!rl&&r
313
MC/DC100%2/2
$result =~ /mmm/u and not $locale
$result =~ /mmm/u not $locale
Truth table100%3/3
A and not(B)
A= $result =~ /mmm/uB= not $locale
ABresult
0X0
100
111
82 7 ▶ $locale = "en" if !$locale;
Branch: 1 branch
BranchTrueFalseTotal
unless $locale 3 4 7
83 7 my $mmm = intToMonths($m,$locale);
84 7 $result =~ s/MMM/$mmm/i;
85 } else {
86 46 $result =~ s/M/$m/;
87 }
88 53 $result =~ s/Y/$y/;
89 53 $result =~ s/D/$d/;
90 53 return $result;
91 }
92  
93 1 ▶sub formatDateFromYYYYMMDD ($;$) {
Subroutine formatDateFromYYYYMMDD: called CC=6 SCAR=21.4
Pod documented
94 1 ▶ return undef if !$_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 1 1
95 1 my ($year,$mon,$day) = $_[0] =~ /(.{4})(..)(..)/;
96 1 ▶ return undef if !$year or !$mon or !$day;
Branch: 1 branch
BranchTrueFalseTotal
unless $year and $mon and $day 0 1 1
Condition33%2/6
$year and $mon and $day
!ll&&!rl&&r
001
$year and $mon
!ll&&!rl&&r
001
MC/DC0%0/3
$year and $mon and $day
$year $mon $day
Truth table25%1/4
A and B and C
A= $yearB= $monC= $day
ABCresult
0XX0
10X0
1100
1111
97 1 ▶ my ($template) = $_[1] if $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 1 0 1
98 1 return formatDate($year,$mon,$day,$template);
99 }
100  
101 5 ▶sub get_curdate_gen (;$) {
Subroutine get_curdate_gen: called CC=1 SCAR=0.0
Pod documented
102 5 my ($template) = @_;
103 5 return formatDate(localtime->year()+ 1900,localtime->mon()+1,localtime->mday(),$template);
104 }
105  
106 1 ▶sub get_curdate_dash {
Subroutine get_curdate_dash: called CC=1 SCAR=0.0
Pod documented
107 1 return sprintf("%02d-%02d-%04d",localtime->mday(), localtime->mon()+1, localtime->year()+ 1900);
108 }
109  
110 6 ▶sub get_curdate_dash_plus_X_years ($;$$) {
Subroutine get_curdate_dash_plus_X_years: called CC=10 SCAR=23.4
Pod documented
111 6 my ($y) = $_[0];
112 6 ▶ return undef if !$y;
Branch: 1 branch
BranchTrueFalseTotal
unless $y 0 6 6
113 6 ▶ my ($year,$mon,$day) = $_[1] =~ /(.{4})(..)(..)/ if $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 4 2 6
114 6 ▶ my $daysToSubtract = $_[2] if $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if $_[2] 1 5 6
115 # date given as second argument: add X years (minus daysToSubtract) from that date
116 6 ▶ if ($year) {
Branch: 1 branch
BranchTrueFalseTotal
if ($year) { } 4 2 6
117 4 my $dateval;
118 4 ▶ $day = 28 if $day eq "29" and !IsLeapYear($year+$y); # regard february in leap years
Branch: 1 branch
BranchTrueFalseTotal
if $day eq 29 and not &IsLeapYear($year + $y) 1 3 4
Condition66%2/3
$day eq 29 and not &IsLeapYear($year + $y)
!ll&&!rl&&r
301
MC/DC50%1/2
$day eq 29 and not &IsLeapYear($year + $y)
$day eq 29 not &IsLeapYear($year + $y)
Truth table66%2/3
A and not(B)
A= $day eq 29B= not &IsLeapYear($year + $y)
ABresult
0X0
100
111
119 4 ▶ if ($daysToSubtract) {
Branch: 1 branch
BranchTrueFalseTotal
if ($daysToSubtract) { } 1 3 4
120 1 $dateval = localtime(timegm_modern(0,0,12,$day,$mon-1,$year)-$daysToSubtract*24*60*60);
121 } else {
122 3 $dateval = localtime(timegm_modern(0,0,12,$day,$mon-1,$year));
123 }
124 4 return sprintf("%02d-%02d-%04d",$dateval->mday(), $dateval->mon()+1, $dateval->year()+1900+$y);
125 } else {
126 # add X years (minus daysToSubtract) from today
127 2 ▶ my $offsetday = (localtime->mday() eq "29" && !IsLeapYear(localtime->year()+ 1900 + $y) ? 1 : 0); # regard february in leap years
Branch: 1 branch
BranchTrueFalseTotal
&EAI::DateUtil::localtime()->mday eq '29' && !&IsLeapYear(&EAI::DateUtil::localtime()->year + 1900 + $y) ? : 0 2 2
Condition33%1/3
&EAI::DateUtil::localtime()->mday eq 29 and not &IsLeapYear(&EAI::DateUtil::localtime()->year + 1900 + $y)
!ll&&!rl&&r
200
MC/DC0%0/2
&EAI::DateUtil::localtime()->mday eq 29 and not &IsLeapYear(&EAI::DateUtil::localtime()->year + 1900 + $y)
&EAI::DateUtil::localtime()->mday eq 29 not &IsLeapYear(&EAI::DateUtil::localtime()->year + 1900 + $y)
Truth table33%1/3
A and not(B)
A= &EAI::DateUtil::localtime()->mday eq 29B= not &IsLeapYear(&EAI::DateUtil::localtime()->year + 1900 + $y)
ABresult
0X0
100
111
128 2 return sprintf("%02d-%02d-%04d",localtime->mday()-$offsetday, localtime->mon()+1, localtime->year()+ 1900 + $y);
129 }
130 }
131  
132 1 ▶sub IsLeapYear ($) {
Subroutine IsLeapYear: called CC=4 SCAR=23.2
Pod undocumented
133 1 my $year = shift;
134 1 ▶ return 0 if $year % 4;
Branch: 1 branch
BranchTrueFalseTotal
if $year % 4 1 0 1
135 0 ▶ return 1 if $year % 100;
Branch: 1 branch
BranchTrueFalseTotal
if $year % 100 0 0 0
136 0 ▶ return 0 if $year % 400;
Branch: 1 branch
BranchTrueFalseTotal
if $year % 400 0 0 0
137 0 return 1;
138 }
139  
140 7 ▶sub get_curtime (;$$) {
Subroutine get_curtime: called CC=4 SCAR=13.9
Pod documented
141 7 my $format = $_[0];
142 7 my $secondsToAdd = $_[1];
143 7 ▶ $format = "%02d:%02d:%02d" if !$format;
Branch: 1 branch
BranchTrueFalseTotal
unless $format 1 6 7
144 7 ▶ if ($secondsToAdd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($secondsToAdd) { } 2 5 7
145 2 my $timeval = localtime(time()+$secondsToAdd);
146 # include 1 before to indicate overflow
147 2 ▶ return ($timeval->mday() ne localtime(time())->mday() ? "1" : "").sprintf($format,$timeval->hour(),$timeval->min(),$timeval->sec());
Branch: 1 branch
BranchTrueFalseTotal
$timeval->mday ne &EAI::DateUtil::localtime(time)->mday ? : 1 1 2
148 } else {
149 5 return sprintf($format,localtime->hour(),localtime->min(),localtime->sec());
150 }
151 }
152  
153 1 ▶sub get_curtime_epochs {
Subroutine get_curtime_epochs: called CC=1 SCAR=0.0
Pod documented
154 1 return time();
155 }
156  
157 1 ▶sub get_curtime_HHMM {
Subroutine get_curtime_HHMM: called CC=1 SCAR=0.0
Pod documented
158 1 return sprintf("%02d%02d",localtime->hour(),localtime->min());
159 }
160  
161 7 ▶sub make_time ($;$) {
Subroutine make_time: called CC=3 SCAR=11.0
Pod documented
162 7 ▶ return undef if !$_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 7 7
163 7 my $secondsToAdd = $_[1];
164 7 ▶ $secondsToAdd = 0 if !$secondsToAdd;
Branch: 1 branch
BranchTrueFalseTotal
unless $secondsToAdd 4 3 7
165 7 my ($hour,$min,$sec) = $_[0] =~ /(..)(..)(..)/;
166 7 return localtime(timelocal_modern($sec,$min,$hour,1,0,1900) + $secondsToAdd);
167 }
168  
169 8 ▶sub formatTime ($;$) {
Subroutine formatTime: called CC=7 SCAR=19.5
Pod documented
170 8 my ($timeval,$format) = @_;
171 8 ▶ $format = "%02d:%02d:%02d" if !$format;
Branch: 1 branch
BranchTrueFalseTotal
unless $format 3 5 8
172 # if $timeval given in epochs create a localtime object first
173 8 ▶ $timeval = localtime($timeval) if ref($timeval) ne "Time::tm";
Branch: 1 branch
BranchTrueFalseTotal
if ref $timeval ne "Time::tm" 1 7 8
174 8 ▶ if ($format =~ /^[^d]*d[^d]*d[^d]*d[^d]*d$/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($format =~ /^[^d]*d[^d]*d[^d]*d[^d]*d$/u) { } 1 7 8
elsif ($format =~ /^[^d]*d[^d]*d[^d]*d$/u) { } 3 4 7
elsif ($format =~ /^[^d]*d[^d]*d$/u) { } 3 1 4
elsif ($format =~ /^[^d]*d$/u) { } 0 1 1
175 # four decimals: day hour min sec (practical in case of overflow)
176 1 return sprintf($format,$timeval->mday()-1,$timeval->hour(),$timeval->min(),$timeval->sec());
177 } elsif ($format =~ /^[^d]*d[^d]*d[^d]*d$/) {
178 # three decimals: hour min sec
179 3 return sprintf($format,$timeval->hour(),$timeval->min(),$timeval->sec());
180 } elsif ($format =~ /^[^d]*d[^d]*d$/) {
181 # two decimals: hour min
182 3 return sprintf($format,$timeval->hour(),$timeval->min());
183 } elsif ($format =~ /^[^d]*d$/) {
184 # one decimal: hour
185 0 return sprintf($format,$timeval->hour());
186 }
187 1 return undef; # error, unsupported format
188 }
189  
190 2 ▶sub is_first_day_of_month ($) {
Subroutine is_first_day_of_month: called CC=6 SCAR=20.7
Pod documented
191 2 ▶ return undef if !$_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 2 2
192 2 my ($y,$m,$d) = $_[0] =~ /(.{4})(..)(..)/;
193 2 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 0 2 2
Condition33%2/6
$y and $m and $d
!ll&&!rl&&r
002
$y and $m
!ll&&!rl&&r
002
MC/DC0%0/3
$y and $m and $d
$y $m $d
Truth table25%1/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
194 2 ▶ ((gmtime(timegm_modern(0,0,12,$d,$m-1,$y)-24*60*60))[4] != $m-1 ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
(gmtime timegm_modern(0, 0, 12, $d, $m - 1, $y) - 86400)[4] != $m - 1 ? : 1 1 2
195 }
196  
197 15 ▶sub is_last_day_of_month ($;$) {
Subroutine is_last_day_of_month: called CC=8 SCAR=21.8
Pod documented
198 15 ▶ return undef if !$_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 15 15
199 15 my ($y,$m,$d) = $_[0] =~ /(.{4})(..)(..)/;
200 15 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 0 15 15
Condition33%2/6
$y and $m and $d
!ll&&!rl&&r
0015
$y and $m
!ll&&!rl&&r
0015
MC/DC0%0/3
$y and $m and $d
$y $m $d
Truth table25%1/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
201 15 my $cal = $_[1];
202 # for respecting holidays add 1 day and compare month
203 15 ▶ if ($cal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cal) { } 10 5 15
204 10 my $shiftedDate = addDaysHol($_[0],1,"YMD",$cal);
205 10 my ($ys,$ms,$ds) = $shiftedDate =~ /(.{4})(..)(..)/;
206 10 ▶ ($ms ne $m ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$ms ne $m ? : 1 9 10
207 } else {
208 5 ▶ ((gmtime(timegm_modern(0,0,12,$d,$m-1,$y) + 24*60*60))[4] != $m-1 ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
(gmtime timegm_modern(0, 0, 12, $d, $m - 1, $y) + 86400)[4] != $m - 1 ? : 3 2 5
209 }
210 }
211 4 ▶sub get_last_day_of_month ($) {
Subroutine get_last_day_of_month: called CC=7 SCAR=20.5
Pod documented
212 4 ▶ return undef if !$_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 4 4
213 4 my ($y,$m,$d) = $_[0] =~ /(.{4})(..)(..)/;
214 4 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 0 4 4
Condition33%2/6
$y and $m and $d
!ll&&!rl&&r
004
$y and $m
!ll&&!rl&&r
004
MC/DC0%0/3
$y and $m and $d
$y $m $d
Truth table25%1/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
215 # first of following month minus 1 day is always last of current month, timegm_modern expects 0 based month, $m is the following month for timegm_modern therefore
216 4 ▶ if ($m == 12) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m == 12) 1 3 4
217 # for December -> January next year
218 1 $m = 0; # month 0 based
219 1 $y++;
220 }
221 4 my $mon = (gmtime(timegm_modern(0,0,12,1,$m,$y) - 24*60*60))[4]+1;
222 4 my $day = (gmtime(timegm_modern(0,0,12,1,$m,$y) - 24*60*60))[3];
223 4 ▶ $y-- if $m == 0; # for December -> reset year again
Branch: 1 branch
BranchTrueFalseTotal
if $m == 0 1 3 4
224 4 return sprintf("%04d%02d%02d",$y, $mon, $day);
225 }
226  
227 9 ▶sub weekday ($) {
Subroutine weekday: called CC=5 SCAR=19.4
Pod documented
228 9 ▶ return undef if !$_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 9 9
229 9 my ($y,$m,$d) = $_[0] =~ /(.{4})(..)(..)/;
230 9 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 0 9 9
Condition33%2/6
$y and $m and $d
!ll&&!rl&&r
009
$y and $m
!ll&&!rl&&r
009
MC/DC0%0/3
$y and $m and $d
$y $m $d
Truth table25%1/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
231 9 (gmtime(timegm_modern(0,0,12,$d,$m-1,$y)))[6]+1;
232 }
233  
234 12 ▶sub is_weekend ($) {
Subroutine is_weekend: called CC=5 SCAR=19.4
Pod documented
235 12 ▶ return undef if !$_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 12 12
236 12 my ($y,$m,$d) = $_[0] =~ /(.{4})(..)(..)/;
237 12 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 0 12 12
Condition33%2/6
$y and $m and $d
!ll&&!rl&&r
0012
$y and $m
!ll&&!rl&&r
0012
MC/DC0%0/3
$y and $m and $d
$y $m $d
Truth table25%1/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
238 12 (gmtime(timegm_modern(0,0,12,$d,$m-1,$y)))[6] =~ /(0|6)/;
239 }
240 # makeMD: argument in timegm_modern form (datetime), returns date in format DDMM (for holiday calculation)
241 607 ▶sub makeMD ($) {
Subroutine makeMD: called CC=2 SCAR=7.2
Pod undocumented
242 607 ▶ return undef if !$_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 607 607
243 607 sprintf("%02d%02d", (gmtime($_[0]))[3],(gmtime($_[0]))[4] + 1);
244 }
245  
246 # British specialties
247 5 ▶sub UKspecial {
Subroutine UKspecial: called CC=8 SCAR=22.1
Pod undocumented
248 5 ▶ return undef if !$_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 5 5
249 5 my ($y,$m,$d) = $_[0] =~ /(.{4})(..)(..)/;
250 5 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 0 5 5
Condition33%2/6
$y and $m and $d
!ll&&!rl&&r
005
$y and $m
!ll&&!rl&&r
005
MC/DC0%0/3
$y and $m and $d
$y $m $d
Truth table25%1/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
251 5 ▶ return 1 if (first_week($d,$m,$y,1,5) || last_week($d,$m,$y,1,5) || last_week($d,$m,$y,1,8));
Branch: 1 branch
BranchTrueFalseTotal
if &first_week($d, $m, $y, 1, 5) or &last_week($d, $m, $y, 1, 5) or &last_week($d, $m, $y, 1, 8) 3 2 5
Condition100%6/6
&first_week($d, $m, $y, 1, 5) or &last_week($d, $m, $y, 1, 5) or &last_week($d, $m, $y, 1, 8)
l!l&&r!l&&!r
212
&first_week($d, $m, $y, 1, 5) or &last_week($d, $m, $y, 1, 5)
l!l&&r!l&&!r
113
MC/DC100%3/3
&first_week($d, $m, $y, 1, 5) or &last_week($d, $m, $y, 1, 5) or &last_week($d, $m, $y, 1, 8)
&first_week($d, $m, $y, 1, 5) &last_week($d, $m, $y, 1, 5) &last_week($d, $m, $y, 1, 8)
Truth table100%4/4
A or B or C
A= &first_week($d, $m, $y, 1, 5)B= &last_week($d, $m, $y, 1, 5)C= &last_week($d, $m, $y, 1, 8)
ABCresult
1XX1
01X1
0011
0000
252 2 return 0;
253 }
254  
255 # fixed holidays
256 6 my %fixedHol = ("BS"=>{"0101"=>1,"0601"=>1,"0105"=>1,"1508"=>1,"2610"=>1,"0111"=>1,"0812"=>1,"2412"=>1,"2512"=>1,"2612"=>1},
257 "BF"=>{"0101"=>1,"0601"=>1,"0105"=>1,"1508"=>1,"2610"=>1,"0111"=>1,"0812"=>1,"2412"=>1,"2512"=>1,"2612"=>1},
258 "AT"=>{"0101"=>1,"0601"=>1,"0105"=>1,"1508"=>1,"2610"=>1,"0111"=>1,"0812"=>1,"2512"=>1,"2612"=>1},
259 "TG"=>{"0101"=>1,"0105"=>1,"2512"=>1,"2612"=>1},
260 "UK"=>{"0101"=>1,"2512"=>1,"2612"=>1}
261 );
262  
263 # easter holidays
264 6 my %easterHol = ("BS"=>{"EM"=>1,"AS"=>1,"WM"=>1,"CC"=>1,"GF"=>1},
265 "BF"=>{"EM"=>1,"AS"=>1,"WM"=>1,"CC"=>1},
266 "AT"=>{"EM"=>1,"AS"=>1,"WM"=>1,"CC"=>1},
267 "TG"=>{"EM"=>1,"GF"=>1},
268 "UK"=>{"EM"=>1,"GF"=>1}
269 );
270  
271 # reference to functions for special holiday calculations
272 6 my %specialHol = ("UK" => \&UKspecial);
273  
274 # adds calendar to DateUtil, first arg name of $cal, second arg fixed holidays hash, third easter holidays hash and fourth special function for additional calculations
275 2 ▶sub addCalendar ($$$$) {
Subroutine addCalendar: called CC=11 SCAR=32.6
Pod documented
276 2 my ($cal,$fixHol,$eastHol,$specialHolSub) = @_;
277 2 ▶ return undef if !$cal or !$fixHol or !$eastHol or !$specialHolSub;
Branch: 1 branch
BranchTrueFalseTotal
unless $cal and $fixHol and $eastHol and $specialHolSub 0 2 2
Condition33%3/9
$cal and $fixHol and $eastHol and $specialHolSub
!ll&&!rl&&r
002
$cal and $fixHol and $eastHol
!ll&&!rl&&r
002
$cal and $fixHol
!ll&&!rl&&r
002
MC/DC0%0/4
$cal and $fixHol and $eastHol and $specialHolSub
$cal $fixHol $eastHol $specialHolSub
Truth table20%1/5
A and B and C and D
A= $calB= $fixHolC= $eastHolD= $specialHolSub
ABCDresult
0XXX0
10XX0
110X0
11100
11111
278 2 ▶ if (defined($fixedHol{$cal})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fixedHol{$cal}) 0 2 2
279 0 cluck("calender <$cal> already implemented for fixed holidays !");
280 0 return 0;
281 }
282 2 ▶ if (defined($easterHol{$cal})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $easterHol{$cal}) 0 2 2
283 0 cluck("calender <$cal> already implemented for easter holidays !");
284 0 return 0;
285 }
286 2 ▶ if (defined($specialHol{$cal})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $specialHol{$cal}) 0 2 2
287 0 cluck("calender <$cal> already implemented for additional calculations !");
288 0 return 0;
289 }
290 2 ▶ $fixedHol{$cal} = ($fixHol ? $fixHol : "");
Branch: 1 branch
BranchTrueFalseTotal
$fixHol ? : 2 0 2
291 2 ▶ $easterHol{$cal} = ($eastHol ? $eastHol : "");
Branch: 1 branch
BranchTrueFalseTotal
$eastHol ? : 2 0 2
292 2 ▶ $specialHol{$cal} = ($specialHolSub ? $specialHolSub : "");
Branch: 1 branch
BranchTrueFalseTotal
$specialHolSub ? : 2 0 2
293 2 return 1;
294 }
295  
296 # check whether second arg is easter in passed calendar (first arg).
297 # requires entry of calendar in %easterHol hash: "$Cal" => {"GF"=>1,"EM"=>1,"ES"=>1,"AS"=>1,"WM"=>1,"CC"=>1}
298 105 ▶sub is_easter ($$) {
Subroutine is_easter: called CC=20 SCAR=32.7
Pod documented
299 105 my ($cal) = $_[0];
300 105 ▶ return undef if !$cal or !$_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $cal and $_[1] 0 105 105
Condition33%1/3
$cal and $_[1]
!ll&&!rl&&r
00105
MC/DC0%0/2
$cal and $_[1]
$cal $_[1]
Truth table33%1/3
A and B
A= $calB= $_[1]
ABresult
0X0
100
111
301 105 my ($y,$m,$d) = $_[1] =~ /(.{4})(..)(..)/;
302 105 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 0 105 105
Condition33%2/6
$y and $m and $d
!ll&&!rl&&r
00105
$y and $m
!ll&&!rl&&r
00105
MC/DC0%0/3
$y and $m and $d
$y $m $d
Truth table25%1/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
303 # first find easter sunday using year
304 105 my $D = (((255 - 11 * ($y % 19)) - 21) % 30) + 21;
305 105 ▶ my $easter = timegm_modern(0,0,12,1,2,$y) + ($D + ($D > 48 ? 1 : 0) + 6 - (($y + int($y / 4) + $D + ($D > 48 ? 1 : 0) + 1) % 7))*86400;
Branch: 2 branches
BranchTrueFalseTotal
$D > 48 ? : 5 100 105
$D > 48 ? : 5 100 105
306 105 ▶ return 1 if makeMD($easter) eq $d.$m and $easterHol{$cal}->{"EH"}; # easter sunday
Branch: 1 branch
BranchTrueFalseTotal
if &makeMD($easter) eq $d . $m and $easterHol{$cal}{"EH"} 0 105 105
Condition33%1/3
&makeMD($easter) eq $d . $m and $easterHol{$cal}{"EH"}
!ll&&!rl&&r
10500
MC/DC0%0/2
&makeMD($easter) eq $d . $m and $easterHol{$cal}{"EH"}
&makeMD($easter) eq $d . $m $easterHol{$cal}{"EH"}
Truth table33%1/3
A and B
A= &makeMD($easter) eq $d . $mB= $easterHol{$cal}{"EH"}
ABresult
0X0
100
111
307 # then the rest
308 105 ▶ return 1 if makeMD($easter-2*86400) eq $d.$m and $easterHol{$cal}->{"GF"}; # good friday
Branch: 1 branch
BranchTrueFalseTotal
if &makeMD($easter - 172800) eq $d . $m and $easterHol{$cal}{"GF"} 2 103 105
Condition100%3/3
&makeMD($easter - 172800) eq $d . $m and $easterHol{$cal}{"GF"}
!ll&&!rl&&r
10032
MC/DC100%2/2
&makeMD($easter - 172800) eq $d . $m and $easterHol{$cal}{"GF"}
&makeMD($easter - 172800) eq $d . $m $easterHol{$cal}{"GF"}
Truth table100%3/3
A and B
A= &makeMD($easter - 172800) eq $d . $mB= $easterHol{$cal}{"GF"}
ABresult
0X0
100
111
309 103 ▶ return 1 if makeMD($easter+1*86400) eq $d.$m and $easterHol{$cal}->{"EM"}; # easter monday
Branch: 1 branch
BranchTrueFalseTotal
if &makeMD($easter + 86400) eq $d . $m and $easterHol{$cal}{"EM"} 3 100 103
Condition66%2/3
&makeMD($easter + 86400) eq $d . $m and $easterHol{$cal}{"EM"}
!ll&&!rl&&r
10003
MC/DC50%1/2
&makeMD($easter + 86400) eq $d . $m and $easterHol{$cal}{"EM"}
&makeMD($easter + 86400) eq $d . $m $easterHol{$cal}{"EM"}
Truth table66%2/3
A and B
A= &makeMD($easter + 86400) eq $d . $mB= $easterHol{$cal}{"EM"}
ABresult
0X0
100
111
310 100 ▶ return 1 if makeMD($easter+39*86400) eq $d.$m and $easterHol{$cal}->{"AS"}; # ascension day
Branch: 1 branch
BranchTrueFalseTotal
if &makeMD($easter + 3369600) eq $d . $m and $easterHol{$cal}{"AS"} 2 98 100
Condition66%2/3
&makeMD($easter + 3369600) eq $d . $m and $easterHol{$cal}{"AS"}
!ll&&!rl&&r
9802
MC/DC50%1/2
&makeMD($easter + 3369600) eq $d . $m and $easterHol{$cal}{"AS"}
&makeMD($easter + 3369600) eq $d . $m $easterHol{$cal}{"AS"}
Truth table66%2/3
A and B
A= &makeMD($easter + 3369600) eq $d . $mB= $easterHol{$cal}{"AS"}
ABresult
0X0
100
111
311 98 ▶ return 1 if makeMD($easter+50*86400) eq $d.$m and $easterHol{$cal}->{"WM"}; # whitmonday
Branch: 1 branch
BranchTrueFalseTotal
if &makeMD($easter + 4320000) eq $d . $m and $easterHol{$cal}{"WM"} 2 96 98
Condition66%2/3
&makeMD($easter + 4320000) eq $d . $m and $easterHol{$cal}{"WM"}
!ll&&!rl&&r
9602
MC/DC50%1/2
&makeMD($easter + 4320000) eq $d . $m and $easterHol{$cal}{"WM"}
&makeMD($easter + 4320000) eq $d . $m $easterHol{$cal}{"WM"}
Truth table66%2/3
A and B
A= &makeMD($easter + 4320000) eq $d . $mB= $easterHol{$cal}{"WM"}
ABresult
0X0
100
111
312 96 ▶ return 1 if makeMD($easter+60*86400) eq $d.$m and $easterHol{$cal}->{"CC"}; # corpus christi day
Branch: 1 branch
BranchTrueFalseTotal
if &makeMD($easter + 5184000) eq $d . $m and $easterHol{$cal}{"CC"} 2 94 96
Condition66%2/3
&makeMD($easter + 5184000) eq $d . $m and $easterHol{$cal}{"CC"}
!ll&&!rl&&r
9402
MC/DC50%1/2
&makeMD($easter + 5184000) eq $d . $m and $easterHol{$cal}{"CC"}
&makeMD($easter + 5184000) eq $d . $m $easterHol{$cal}{"CC"}
Truth table66%2/3
A and B
A= &makeMD($easter + 5184000) eq $d . $mB= $easterHol{$cal}{"CC"}
ABresult
0X0
100
111
313 94 return 0;
314 }
315  
316 # check whether second arg is holiday in passed calendar (first arg)
317 163 ▶sub is_holiday ($$) {
Subroutine is_holiday: called CC=14 SCAR=30.1
Pod documented
318 163 my ($cal) = $_[0];
319 163 ▶ return undef if !$cal or $cal eq "WE" or !$_[1]; # weekends are checked with "is_weekend", so no holiday passed here! Same for empty dates passed
Branch: 1 branch
BranchTrueFalseTotal
if not $cal or $cal eq "WE" or not $_[1] 10 153 163
Condition66%4/6
not $cal or $cal eq "WE" or not $_[1]
l!l&&r!l&&!r
100153
not $cal or $cal eq "WE"
l!l&&r!l&&!r
010153
MC/DC33%1/3
not $cal or $cal eq "WE" or not $_[1]
not $cal $cal eq "WE" not $_[1]
Truth table50%2/4
not(A) or B or not(C)
A= not $calB= $cal eq "WE"C= not $_[1]
ABCresult
1XX1
01X1
0011
0000
320 153 my ($y,$m,$d) = $_[1] =~ /(.{4})(..)(..)/;
321 153 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 0 153 153
Condition33%2/6
$y and $m and $d
!ll&&!rl&&r
00153
$y and $m
!ll&&!rl&&r
00153
MC/DC0%0/3
$y and $m and $d
$y $m $d
Truth table25%1/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
322 153 ▶ return 1 if $fixedHol{$cal}->{$d.$m};
Branch: 1 branch
BranchTrueFalseTotal
if $fixedHol{$cal}{$d . $m} 48 105 153
323 105 ▶ return 1 if is_easter($cal,$_[1]);
Branch: 1 branch
BranchTrueFalseTotal
if &is_easter($cal, $_[1]) 11 94 105
324 94 ▶ return 1 if $specialHol{$cal} and $specialHol{$cal}->($_[1]);
Branch: 1 branch
BranchTrueFalseTotal
if $specialHol{$cal} and $specialHol{$cal}->($_[1]) 5 89 94
Condition100%3/3
$specialHol{$cal} and $specialHol{$cal}->($_[1])
!ll&&!rl&&r
8725
MC/DC100%2/2
$specialHol{$cal} and $specialHol{$cal}->($_[1])
$specialHol{$cal} $specialHol{$cal}->($_[1])
Truth table100%3/3
A and B
A= $specialHol{$cal}B= $specialHol{$cal}->($_[1])
ABresult
0X0
100
111
325 89 ▶ unless ($fixedHol{$cal} or $easterHol{$cal} or $specialHol{$cal}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fixedHol{$cal} or $easterHol{$cal} or $specialHol{$cal}) 0 89 89
Condition33%2/6
$fixedHol{$cal} or $easterHol{$cal} or $specialHol{$cal}
l!l&&r!l&&!r
8900
$fixedHol{$cal} or $easterHol{$cal}
l!l&&r!l&&!r
8900
MC/DC0%0/3
$fixedHol{$cal} or $easterHol{$cal} or $specialHol{$cal}
$fixedHol{$cal} $easterHol{$cal} $specialHol{$cal}
Truth table25%1/4
A or B or C
A= $fixedHol{$cal}B= $easterHol{$cal}C= $specialHol{$cal}
ABCresult
1XX1
01X1
0011
0000
326 0 cluck("calender <$cal> neither implemented in \$fixedHol{$cal} nor \$easterHol{$cal} nor \$specialHol{$cal} !");
327 0 return 0;
328 }
329 89 return 0;
330 }
331  
332 19 ▶sub first_week ($$$$;$) {
Subroutine first_week: called CC=12 SCAR=29.5
Pod documented
333 19 my ($d,$m,$y,$day,$month) = @_;
334 19 ▶ return undef if !$y or !$m or !$d or !defined($day);
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d and defined $day 0 19 19
Condition33%3/9
$y and $m and $d and defined $day
!ll&&!rl&&r
0019
$y and $m and $d
!ll&&!rl&&r
0019
$y and $m
!ll&&!rl&&r
0019
MC/DC0%0/4
$y and $m and $d and defined $day
$y $m $d defined $day
Truth table20%1/5
A and B and C and D
A= $yB= $mC= $dD= defined $day
ABCDresult
0XXX0
10XX0
110X0
11100
11111
335 19 ▶ $month = $m if !$month;
Branch: 1 branch
BranchTrueFalseTotal
unless $month 0 19 19
336 19 ▶ unless ((0 <= $day) and ( $day <= 6)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (0 <= $day and $day <= 6) 0 19 19
Condition33%1/3
0 <= $day and $day <= 6
!ll&&!rl&&r
0019
MC/DC0%0/2
0 <= $day and $day <= 6
0 <= $day $day <= 6
Truth table33%1/3
A and B
A= 0 <= $dayB= $day <= 6
ABresult
0X0
100
111
337 0 cluck("day <$day> is out of range 0 - 6 (sunday==0)");
338 0 return 0;
339 }
340 19 my $date = localtime(timelocal_modern(0,0,12,$d,$m-1,$y));
341 19 ▶ return 0 unless $m == $month; # return unless the month matches
Branch: 1 branch
BranchTrueFalseTotal
unless $m == $month 1 18 19
342 18 ▶ return 0 if $d > 7; # can't be the first week of the month if day is after the 7th
Branch: 1 branch
BranchTrueFalseTotal
if $d > 7 2 16 18
343 16 ▶ return 0 unless $date->wday() == $day; # return unless the (week)day matches
Branch: 1 branch
BranchTrueFalseTotal
unless $date->wday == $day 4 12 16
344 12 ▶ return 0 unless (localtime(timelocal_modern(0,0,12,$d,$m-1,$y)-7*24*60*60))->mon() != $m-1; # return unless 1 week earlier we're in a different month
Branch: 1 branch
BranchTrueFalseTotal
unless &EAI::DateUtil::localtime(timelocal_modern(0, 0, 12, $d, $m - 1, $y) - 604800)->mon != $m - 1 0 12 12
345 12 return 1;
346 }
347  
348 9 ▶sub first_weekYYYYMMDD ($$;$) {
Subroutine first_weekYYYYMMDD: called CC=7 SCAR=22.7
Pod documented
349 9 my ($date,$day,$month) = @_;
350 9 ▶ return undef if !$date or !defined($day);
Branch: 1 branch
BranchTrueFalseTotal
unless $date and defined $day 0 9 9
Condition33%1/3
$date and defined $day
!ll&&!rl&&r
009
MC/DC0%0/2
$date and defined $day
$date defined $day
Truth table33%1/3
A and B
A= $dateB= defined $day
ABresult
0X0
100
111
351 9 my ($y,$m,$d) = $date =~ /(.{4})(..)(..)/;
352 9 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 0 9 9
Condition33%2/6
$y and $m and $d
!ll&&!rl&&r
009
$y and $m
!ll&&!rl&&r
009
MC/DC0%0/3
$y and $m and $d
$y $m $d
Truth table25%1/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
353 9 ▶ $month = $m if !$month;
Branch: 1 branch
BranchTrueFalseTotal
unless $month 8 1 9
354 9 return first_week ($d,$m,$y,$day,$month);
355 }
356  
357 14 ▶sub last_week ($$$$;$) {
Subroutine last_week: called CC=11 SCAR=29.3
Pod documented
358 14 my ($d,$m,$y,$day,$month) = @_;
359 14 ▶ return undef if !$y or !$m or !$d or !defined($day);
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d and defined $day 0 14 14
Condition33%3/9
$y and $m and $d and defined $day
!ll&&!rl&&r
0014
$y and $m and $d
!ll&&!rl&&r
0014
$y and $m
!ll&&!rl&&r
0014
MC/DC0%0/4
$y and $m and $d and defined $day
$y $m $d defined $day
Truth table20%1/5
A and B and C and D
A= $yB= $mC= $dD= defined $day
ABCDresult
0XXX0
10XX0
110X0
11100
11111
360 14 ▶ $month = $m if !$month;
Branch: 1 branch
BranchTrueFalseTotal
unless $month 0 14 14
361 14 ▶ unless ((0 <= $day) and ( $day <= 6)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (0 <= $day and $day <= 6) 0 14 14
Condition33%1/3
0 <= $day and $day <= 6
!ll&&!rl&&r
0014
MC/DC0%0/2
0 <= $day and $day <= 6
0 <= $day $day <= 6
Truth table33%1/3
A and B
A= 0 <= $dayB= $day <= 6
ABresult
0X0
100
111
362 0 cluck("day <$day> is out of range 0 - 6 (sunday==0)");
363 0 return 0;
364 }
365 14 my $date = localtime(timelocal_modern(0,0,12,$d,$m-1,$y));
366 14 ▶ return 0 unless $m == $month; # return unless the month matches
Branch: 1 branch
BranchTrueFalseTotal
unless $m == $month 3 11 14
367 11 ▶ return 0 unless $date->wday() == $day; # return unless the (week)day matches
Branch: 1 branch
BranchTrueFalseTotal
unless $date->wday == $day 3 8 11
368 8 ▶ return 0 unless (localtime(timelocal_modern(0,0,12,$d,$m-1,$y)+7*24*60*60))->mon() != $m-1; # return unless 1 week later we're in a different month
Branch: 1 branch
BranchTrueFalseTotal
unless &EAI::DateUtil::localtime(timelocal_modern(0, 0, 12, $d, $m - 1, $y) + 604800)->mon != $m - 1 0 8 8
369 8 return 1;
370 }
371  
372 2 ▶sub last_weekYYYYMMDD ($$;$) {
Subroutine last_weekYYYYMMDD: called CC=4 SCAR=14.5
Pod documented
373 2 my ($date,$day,$month) = @_;
374 2 ▶ return undef if !$date or !defined($day);
Branch: 1 branch
BranchTrueFalseTotal
unless $date and defined $day 0 2 2
Condition33%1/3
$date and defined $day
!ll&&!rl&&r
002
MC/DC0%0/2
$date and defined $day
$date defined $day
Truth table33%1/3
A and B
A= $dateB= defined $day
ABresult
0X0
100
111
375 2 my ($y,$m,$d) = $date =~ /(.{4})(..)(..)/;
376 2 ▶ $month = $m if !$month;
Branch: 1 branch
BranchTrueFalseTotal
unless $month 1 1 2
377 2 return last_week ($d,$m,$y,$day,$month);
378 }
379  
380 0 ▶sub convertDate ($) {
Subroutine convertDate: not called CC=2 SCAR=17.9
Pod documented
381 0 ▶ return undef if !$_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 0 0
382 0 my ($y,$m,$d) = ($_[0] =~ /(\d{4})[.\/](\d\d)[.\/](\d\d)/);
383 0 return sprintf("%04d%02d%02d",$y, $m, $d);
384 }
385  
386 0 ▶sub convertDateFromMMM ($$$$;$) {
Subroutine convertDateFromMMM: not called CC=6 SCAR=37.4
Pod documented
387 0 my ($inDate,$day,$mon,$year,$locale) = @_;
388 0 ▶ return undef if !$inDate or !$day or !$mon or !$year;
Branch: 1 branch
BranchTrueFalseTotal
unless $inDate and $day and $mon and $year 0 0 0
Condition0%0/9
$inDate and $day and $mon and $year
!ll&&!rl&&r
000
$inDate and $day and $mon
!ll&&!rl&&r
000
$inDate and $day
!ll&&!rl&&r
000
MC/DC0%0/4
$inDate and $day and $mon and $year
$inDate $day $mon $year
Truth table0%0/5
A and B and C and D
A= $inDateB= $dayC= $monD= $year
ABCDresult
0XXX0
10XX0
110X0
11100
11111
389 0 ▶ $locale = "en" if !$locale;
Branch: 1 branch
BranchTrueFalseTotal
unless $locale 0 0 0
390 0 my ($d,$m,$y) = ($inDate =~ /(\d{2})-(\w{3})-(\d{4})/);
391 0 $$day = $d;
392 0 $$mon = $monthsToInt{lc($locale)}{lc($m)};
393 0 $$year = $y;
394 0 return sprintf("%02d.%02d.%04d",$d, $$mon, $y);
395 }
396  
397 0 ▶sub convertDateToMMM ($$$;$) {
Subroutine convertDateToMMM: not called CC=5 SCAR=34.0
Pod documented
398 0 my ($day,$mon,$year,$locale) = @_;
399 0 ▶ return undef if !$day or !$mon or !$year;
Branch: 1 branch
BranchTrueFalseTotal
unless $day and $mon and $year 0 0 0
Condition0%0/6
$day and $mon and $year
!ll&&!rl&&r
000
$day and $mon
!ll&&!rl&&r
000
MC/DC0%0/3
$day and $mon and $year
$day $mon $year
Truth table0%0/4
A and B and C
A= $dayB= $monC= $year
ABCresult
0XX0
10X0
1100
1111
400 0 ▶ $locale = "en" if !$locale;
Branch: 1 branch
BranchTrueFalseTotal
unless $locale 0 0 0
401 0 return sprintf("%02d-%03s-%04d",$day, $intTomonths{lc($locale)}[$mon-1], $year);
402 }
403  
404 0 ▶sub convertToDDMMYYYY ($) {
Subroutine convertToDDMMYYYY: not called CC=4 SCAR=30.0
Pod documented
405 0 my ($y,$m,$d) = $_[0] =~ /(.{4})(..)(..)/;
406 0 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 0 0 0
Condition0%0/6
$y and $m and $d
!ll&&!rl&&r
000
$y and $m
!ll&&!rl&&r
000
MC/DC0%0/3
$y and $m and $d
$y $m $d
Truth table0%0/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
407 0 return "$d.$m.$y";
408 }
409  
410 1 ▶sub addDays ($$$$;$) {
Subroutine addDays: called CC=6 SCAR=20.5
Pod documented
411 1 my ($day,$mon,$year,$dayDiff,$locale) = @_;
412 1 ▶ return undef if !$day or !$mon or !$year or !$dayDiff;
Branch: 1 branch
BranchTrueFalseTotal
unless $day and $mon and $year and $dayDiff 0 1 1
Condition33%3/9
$day and $mon and $year and $dayDiff
!ll&&!rl&&r
001
$day and $mon and $year
!ll&&!rl&&r
001
$day and $mon
!ll&&!rl&&r
001
MC/DC0%0/4
$day and $mon and $year and $dayDiff
$day $mon $year $dayDiff
Truth table20%1/5
A and B and C and D
A= $dayB= $monC= $yearD= $dayDiff
ABCDresult
0XXX0
10XX0
110X0
11100
11111
413 1 ▶ $locale = "en" if !$locale;
Branch: 1 branch
BranchTrueFalseTotal
unless $locale 1 0 1
414 1 my $curDateEpoch = timelocal_modern(0,0,0,$$day,$$mon-1,$$year);
415 1 my $diffDate = localtime($curDateEpoch + $dayDiff * 60 * 60 * 24);
416 # dereference, so the passed variable is changed
417 1 $$year = $diffDate->year+1900;
418 1 $$mon = $diffDate->mon+1;
419 1 $$day = $diffDate->mday;
420 1 return sprintf("%02d-%03s-%04d",$$day, $intTomonths{lc($locale)}[$$mon-1], $$year);
421 }
422  
423 0 ▶sub subtractDays ($$) {
Subroutine subtractDays: not called CC=5 SCAR=34.0
Pod documented
424 0 my ($date,$days) = @_;
425 0 ▶ return undef if !$date;
Branch: 1 branch
BranchTrueFalseTotal
unless $date 0 0 0
426 0 my ($y,$m,$d) = $date =~ /(.{4})(..)(..)/;
427 0 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 0 0 0
Condition0%0/6
$y and $m and $d
!ll&&!rl&&r
000
$y and $m
!ll&&!rl&&r
000
MC/DC0%0/3
$y and $m and $d
$y $m $d
Truth table0%0/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
428 0 my $theDate = localtime(timelocal_modern(0,0,12,$d,$m-1,$y) - $days*24*60*60);
429 0 return sprintf("%04d%02d%02d",$theDate->year()+ 1900, $theDate->mon()+1, $theDate->mday());
430 }
431  
432 27 ▶sub addDaysHol ($$;$$) {
Subroutine addDaysHol: called CC=10 SCAR=23.1
Pod documented
433 27 my ($date, $days, $template, $cal) = @_;
434 27 ▶ $cal="NO" if !$cal;
Branch: 1 branch
BranchTrueFalseTotal
unless $cal 1 26 27
435 27 ▶ return undef if !$date;
Branch: 1 branch
BranchTrueFalseTotal
unless $date 0 27 27
436 27 my ($y,$m,$d) = $date =~ /(.{4})(..)(..)/;
437 27 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 1 26 27
Condition66%4/6
$y and $m and $d
!ll&&!rl&&r
1026
$y and $m
!ll&&!rl&&r
1026
MC/DC33%1/3
$y and $m and $d
$y $m $d
Truth table50%2/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
438 # first add days
439 26 my $refdate = localtime(timelocal_modern(0,0,12,$d,$m-1,$y) + $days*24*60*60);
440 # then add further days as long weekend or holidays
441 26 ▶ if ($cal ne "NO") {
Branch: 1 branch
BranchTrueFalseTotal
if ($cal ne "NO") 25 1 26
442 25 ▶ while ($refdate->wday() == 0 || $refdate->wday() == 6 || is_holiday($cal,sprintf("%04d%02d%02d", $refdate->year()+1900, $refdate->mon()+1, $refdate->mday()))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($refdate->wday == 0 or $refdate->wday == 6 or &is_holiday($cal, sprintf("%04d%02d%02d", $refdate->year + 1900, $refdate->mon + 1, $refdate->mday))) 22 25 47
Condition100%6/6
$refdate->wday == 0 or $refdate->wday == 6 or &is_holiday($cal, sprintf("%04d%02d%02d", $refdate->year + 1900, $refdate->mon + 1, $refdate->mday))
l!l&&r!l&&!r
91325
$refdate->wday == 0 or $refdate->wday == 6
l!l&&r!l&&!r
5438
MC/DC100%3/3
$refdate->wday == 0 or $refdate->wday == 6 or &is_holiday($cal, sprintf("%04d%02d%02d", $refdate->year + 1900, $refdate->mon + 1, $refdate->mday))
$refdate->wday == 0 $refdate->wday == 6 &is_holiday($cal, sprintf("%04d%02d%02d", $refdate->year + 1900, $refdate->mon + 1, $refdate->mday))
Truth table100%4/4
A or B or C
A= $refdate->wday == 0B= $refdate->wday == 6C= &is_holiday($cal, sprintf("%04d%02d%02d", $refdate->year + 1900, $refdate->mon + 1, $refdate->mday))
ABCresult
1XX1
01X1
0011
0000
443 22 $refdate = localtime(timelocal_modern(0,0,12,$refdate->mday(),$refdate->mon(),$refdate->year()+1900) + 24*60*60);
444 }
445 }
446 26 return formatDate($refdate->year()+1900, $refdate->mon()+1, $refdate->mday(),$template);
447 }
448  
449 12 ▶sub subtractDaysHol ($$;$$) {
Subroutine subtractDaysHol: called CC=10 SCAR=23.1
Pod documented
450 12 my ($date,$days,$template,$cal) = @_;
451 12 ▶ $cal="NO" if !$cal;
Branch: 1 branch
BranchTrueFalseTotal
unless $cal 1 11 12
452 12 ▶ return undef if !$date;
Branch: 1 branch
BranchTrueFalseTotal
unless $date 0 12 12
453 12 my ($y,$m,$d) = $date =~ /(.{4})(..)(..)/;
454 12 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 1 11 12
Condition66%4/6
$y and $m and $d
!ll&&!rl&&r
1011
$y and $m
!ll&&!rl&&r
1011
MC/DC33%1/3
$y and $m and $d
$y $m $d
Truth table50%2/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
455 # first subtract days
456 11 my $refdate = localtime(timelocal_modern(0,0,12,$d,$m-1,$y) - $days*24*60*60);
457 # then subtract further days as long weekend or holidays
458 11 ▶ if ($cal ne "NO") {
Branch: 1 branch
BranchTrueFalseTotal
if ($cal ne "NO") 10 1 11
459 10 ▶ while ($refdate->wday() == 0 || $refdate->wday() == 6 || is_holiday($cal, sprintf("%04d%02d%02d", $refdate->year()+1900, $refdate->mon()+1, $refdate->mday()))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($refdate->wday == 0 or $refdate->wday == 6 or &is_holiday($cal, sprintf("%04d%02d%02d", $refdate->year + 1900, $refdate->mon + 1, $refdate->mday))) 12 10 22
Condition100%6/6
$refdate->wday == 0 or $refdate->wday == 6 or &is_holiday($cal, sprintf("%04d%02d%02d", $refdate->year + 1900, $refdate->mon + 1, $refdate->mday))
l!l&&r!l&&!r
8410
$refdate->wday == 0 or $refdate->wday == 6
l!l&&r!l&&!r
4414
MC/DC100%3/3
$refdate->wday == 0 or $refdate->wday == 6 or &is_holiday($cal, sprintf("%04d%02d%02d", $refdate->year + 1900, $refdate->mon + 1, $refdate->mday))
$refdate->wday == 0 $refdate->wday == 6 &is_holiday($cal, sprintf("%04d%02d%02d", $refdate->year + 1900, $refdate->mon + 1, $refdate->mday))
Truth table100%4/4
A or B or C
A= $refdate->wday == 0B= $refdate->wday == 6C= &is_holiday($cal, sprintf("%04d%02d%02d", $refdate->year + 1900, $refdate->mon + 1, $refdate->mday))
ABCresult
1XX1
01X1
0011
0000
460 12 $refdate = localtime(timelocal_modern(0,0,12,$refdate->mday(),$refdate->mon(),$refdate->year()+1900) - 24*60*60);
461 }
462 }
463 11 return formatDate($refdate->year()+1900, $refdate->mon()+1, $refdate->mday(),$template);
464 }
465  
466 5 ▶sub addDatePart {
Subroutine addDatePart: called CC=6 SCAR=19.9
Pod documented
467 5 my ($date, $count, $datepart, $template) = @_;
468 5 ▶ return if !$date;
Branch: 1 branch
BranchTrueFalseTotal
unless $date 0 5 5
469 5 my %datepart = (d=>3,m=>4,y=>5,day=>3,mon=>4,year=>5,D=>3,M=>4,Y=>5,month=>4);
470 5 my ($y,$m,$d) = $date =~ /(.{4})(..)(..)/;
471 5 ▶ return undef if !$y or !$m or !$d;
Branch: 1 branch
BranchTrueFalseTotal
unless $y and $m and $d 0 5 5
Condition33%2/6
$y and $m and $d
!ll&&!rl&&r
005
$y and $m
!ll&&!rl&&r
005
MC/DC0%0/3
$y and $m and $d
$y $m $d
Truth table25%1/4
A and B and C
A= $yB= $mC= $d
ABCresult
0XX0
10X0
1100
1111
472 5 my $parts = localtime(timelocal_modern(0,0,12,$d,$m-1,$y));
473 5 ▶ @$parts[$datepart{$datepart}] += $count if $datepart{$datepart};
Branch: 1 branch
BranchTrueFalseTotal
if $datepart{$datepart} 5 0 5
474 5 my $refdate =localtime(mktime @$parts);
475 5 return formatDate($refdate->year()+1900, $refdate->mon()+1, $refdate->mday(),$template);
476 }
477  
478 0 ▶sub get_lastdateYYYYMMDD {
Subroutine get_lastdateYYYYMMDD: not called CC=2 SCAR=17.9
Pod documented
479 0 my $refdate = time - 24*60*60;
480 0 ▶ $refdate = time - 3*24*60*60 if (localtime->wday() == 1);
Branch: 1 branch
BranchTrueFalseTotal
if &EAI::DateUtil::localtime()->wday == 1 0 0 0
481 0 return sprintf("%04d%02d%02d",localtime($refdate)->year() + 1900, localtime($refdate)->mon()+1, localtime($refdate)->mday());
482 }
483  
484 0 ▶sub get_lastdateDDMMYYYY {
Subroutine get_lastdateDDMMYYYY: not called CC=2 SCAR=17.9
Pod documented
485 0 my $refdate = time - 24*60*60;
486 0 ▶ $refdate = time - 3*24*60*60 if (localtime->wday() == 1);
Branch: 1 branch
BranchTrueFalseTotal
if &EAI::DateUtil::localtime()->wday == 1 0 0 0
487 0 return sprintf("%02d.%02d.%04d",localtime($refdate)->mday(), localtime($refdate)->mon()+1, localtime($refdate)->year() + 1900);
488 }
489  
490 0 ▶sub convertcomma ($;$) {
Subroutine convertcomma: not called CC=3 SCAR=24.8
Pod documented
491 0 my ($number, $divideBy) = @_;
492 0 ▶ return undef if !defined($number);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 0 0 0
493 0 ▶ $number = $number / $divideBy if $divideBy;
Branch: 1 branch
BranchTrueFalseTotal
if $divideBy 0 0 0
494 0 $number = "$number";
495 0 $number =~ s/\./,/;
496 0 return $number;
497 }
498  
499 7 ▶sub convertToThousendDecimal ($;$) {
Subroutine convertToThousendDecimal: called CC=6 SCAR=17.9
Pod documented
500 7 my ($value,$ignoreDecimal) = @_;
501 7 ▶ return undef if !defined($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 7 7
502 7 my ($negSign) = ($value =~ /(-).*?/);
503 7 ▶ $negSign = "" if !defined($negSign);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $negSign 5 2 7
504 7 $value =~ s/-//;
505 # get digits before decimal point and after (optionally divided by thousand separator ".")
506 7 ▶ my ($intplaces,$decplaces) = $value =~ /(\d*)\.(\d*)/ if $value =~ /\./;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\./u 3 4 7
507 7 ▶ if ($value !~ /\./) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ /\./u) 4 3 7
508 4 $intplaces = $value;
509 4 $decplaces = "0";
510 }
511 # converts digits before decimal point to thousand separated number
512 7 my $quantity = reverse join '.', unpack '(A3)*', reverse $intplaces;
513 7 ▶ $quantity = $negSign.$quantity.($ignoreDecimal ? "" : ",".$decplaces);
Branch: 1 branch
BranchTrueFalseTotal
$ignoreDecimal ? : 3 4 7
514 7 return $quantity;
515 }
516  
517 1 ▶sub get_dateseries ($$;$) {
Subroutine get_dateseries: called CC=14 SCAR=30.4
Pod documented
518 1 my ($fromDate,$toDate,$cal) = @_;
519 1 ▶ return undef if !$fromDate or !$toDate;
Branch: 1 branch
BranchTrueFalseTotal
unless $fromDate and $toDate 0 1 1
Condition33%1/3
$fromDate and $toDate
!ll&&!rl&&r
001
MC/DC0%0/2
$fromDate and $toDate
$fromDate $toDate
Truth table33%1/3
A and B
A= $fromDateB= $toDate
ABresult
0X0
100
111
520 1 my ($yf,$mf,$df) = $fromDate =~ /(.{4})(..)(..)/;
521 1 my ($yt,$mt,$dt) = $toDate =~ /(.{4})(..)(..)/;
522 1 ▶ return undef if !$yf or !$mf or !$df or !$yt or !$mt or !$dt;
Branch: 1 branch
BranchTrueFalseTotal
unless $yf and $mf and $df and $yt and $mt and $dt 0 1 1
Condition33%5/15
$yf and $mf and $df and $yt and $mt and $dt
!ll&&!rl&&r
001
$yf and $mf and $df and $yt and $mt
!ll&&!rl&&r
001
$yf and $mf and $df and $yt
!ll&&!rl&&r
001
$yf and $mf and $df
!ll&&!rl&&r
001
$yf and $mf
!ll&&!rl&&r
001
MC/DC0%0/6
$yf and $mf and $df and $yt and $mt and $dt
$yf $mf $df $yt $mt $dt
Truth table14%1/7
A and B and C and D and E and F
A= $yfB= $mfC= $dfD= $ytE= $mtF= $dt
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
523 1 my $from = timelocal_modern(0,0,12,$df,$mf-1,$yf);
524 1 my $to = timelocal_modern(0,0,12,$dt,$mt-1,$yt);
525 1 my @dateseries;
526 1 ▶ for ($_= $from; $_<= $to; $_ += 24*60*60) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ <= $to) 60 1 61
527 60 my $date = localtime($_);
528 60 my $datestr = sprintf("%04d%02d%02d",$date->year()+1900,$date->mon()+1,$date->mday());
529 60 ▶ if ($cal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cal) { } 60 0 60
530 60 ▶ push @dateseries, $datestr if $date->wday() != 0 and $date->wday() != 6 and !is_holiday($cal,$datestr);
Branch: 1 branch
BranchTrueFalseTotal
if $date->wday != 0 and $date->wday != 6 and not &is_holiday($cal, $datestr) 41 19 60
Condition100%6/6
$date->wday != 0 and $date->wday != 6 and not &is_holiday($cal, $datestr)
!ll&&!rl&&r
18141
$date->wday != 0 and $date->wday != 6
!ll&&!rl&&r
9942
MC/DC100%3/3
$date->wday != 0 and $date->wday != 6 and not &is_holiday($cal, $datestr)
$date->wday != 0 $date->wday != 6 not &is_holiday($cal, $datestr)
Truth table100%4/4
A and B and not(C)
A= $date->wday != 0B= $date->wday != 6C= not &is_holiday($cal, $datestr)
ABCresult
0XX0
10X0
1100
1111
531 } else {
532 0 push @dateseries, $datestr;
533 }
534 }
535 1 return @dateseries;
536 }
537  
538 6 ▶sub parseFromDDMMYYYY ($) {
Subroutine parseFromDDMMYYYY: called CC=10 SCAR=24.8
Pod documented
539 6 my ($dateStr) = @_;
540 6 ▶ return undef if !$dateStr;
Branch: 1 branch
BranchTrueFalseTotal
unless $dateStr 0 6 6
541 6 my ($df,$mf,$yf) = $dateStr =~ /(..*)\.(..*)\.(.{4})/;
542 6 ▶ return undef if !$yf or !$mf or !$df;
Branch: 1 branch
BranchTrueFalseTotal
unless $yf and $mf and $df 0 6 6
Condition33%2/6
$yf and $mf and $df
!ll&&!rl&&r
006
$yf and $mf
!ll&&!rl&&r
006
MC/DC0%0/3
$yf and $mf and $df
$yf $mf $df
Truth table25%1/4
A and B and C
A= $yfB= $mfC= $df
ABCresult
0XX0
10X0
1100
1111
543 6 ▶ return undef if !($yf >= 1900) or !($mf >= 1 and $mf <= 12) or !($df >= 1 and $df <= 31);
Branch: 1 branch
BranchTrueFalseTotal
unless $yf >= 1900 and ($mf >= 1 and $mf <= 12) and ($df >= 1 and $df <= 31) 3 3 6
Condition83%10/12
$yf >= 1900 and ($mf >= 1 and $mf <= 12) and ($df >= 1 and $df <= 31)
!ll&&!rl&&r
213
$yf >= 1900 and ($mf >= 1 and $mf <= 12)
!ll&&!rl&&r
114
$mf >= 1 and $mf <= 12
!ll&&!rl&&r
014
$df >= 1 and $df <= 31
!ll&&!rl&&r
103
MC/DC60%3/5
$yf >= 1900 and ($mf >= 1 and $mf <= 12) and ($df >= 1 and $df <= 31)
$yf >= 1900 $mf >= 1 $mf <= 12 $df >= 1 $df <= 31
Truth table66%4/6
A and B and C and D and E
A= $yf >= 1900B= $mf >= 1C= $mf <= 12D= $df >= 1E= $df <= 31
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
544 3 return timelocal_modern(0,0,0,$df,$mf-1,$yf);
545 }
546  
547 8 ▶sub parseFromYYYYMMDD ($) {
Subroutine parseFromYYYYMMDD: called CC=11 SCAR=28.2
Pod documented
548 8 my ($dateStr) = @_;
549 8 ▶ return undef if !$dateStr;
Branch: 1 branch
BranchTrueFalseTotal
unless $dateStr 1 7 8
550 7 my ($yf,$mf,$df) = $dateStr =~ /(.{4})(..)(..)/;
551 7 ▶ return undef if !$yf or !$mf or !$df;
Branch: 1 branch
BranchTrueFalseTotal
unless $yf and $mf and $df 0 7 7
Condition33%2/6
$yf and $mf and $df
!ll&&!rl&&r
007
$yf and $mf
!ll&&!rl&&r
007
MC/DC0%0/3
$yf and $mf and $df
$yf $mf $df
Truth table25%1/4
A and B and C
A= $yfB= $mfC= $df
ABCresult
0XX0
10X0
1100
1111
552 7 ▶ return undef if !$dateStr or !($yf >= 1900) or !($mf >= 1 and $mf <= 12) or !($df >= 1 and $df <= 31);
Branch: 1 branch
BranchTrueFalseTotal
unless $dateStr and $yf >= 1900 and ($mf >= 1 and $mf <= 12) and ($df >= 1 and $df <= 31) 2 5 7
Condition53%8/15
$dateStr and $yf >= 1900 and ($mf >= 1 and $mf <= 12) and ($df >= 1 and $df <= 31)
!ll&&!rl&&r
025
$dateStr and $yf >= 1900 and ($mf >= 1 and $mf <= 12)
!ll&&!rl&&r
007
$dateStr and $yf >= 1900
!ll&&!rl&&r
007
$mf >= 1 and $mf <= 12
!ll&&!rl&&r
007
$df >= 1 and $df <= 31
!ll&&!rl&&r
115
MC/DC33%2/6
$dateStr and $yf >= 1900 and ($mf >= 1 and $mf <= 12) and ($df >= 1 and $df <= 31)
$dateStr $yf >= 1900 $mf >= 1 $mf <= 12 $df >= 1 $df <= 31
Truth table42%3/7
A and B and C and D and E and F
A= $dateStrB= $yf >= 1900C= $mf >= 1D= $mf <= 12E= $df >= 1F= $df <= 31
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
553 5 return timelocal_modern(0,0,0,$df,$mf-1,$yf);
554 }
555  
556 2 ▶sub convertEpochToYYYYMMDD ($) {
Subroutine convertEpochToYYYYMMDD: called CC=3 SCAR=11.0
Pod documented
557 2 my ($arg) = @_;
558 2 ▶ if (ref($arg) eq 'Time::Piece') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $arg eq 'Time::Piece') { } 1 1 2
elsif ($arg) { } 1 0 1
559 1 return sprintf("%04d%02d%02d",$arg->year(),$arg->mon(),$arg->mday());
560 } elsif($arg) {
561 1 my $date = localtime($arg);
562 1 return sprintf("%04d%02d%02d",$date->year()+1900,$date->mon()+1,$date->mday());
563 }
564 }
565  
566 1 ▶sub convertJulianToYYYYMMDD ($) {
Subroutine convertJulianToYYYYMMDD: called CC=1 SCAR=0.0
Pod documented
567 1 my ($arg) = @_;
568 # excel calculates 0 as being 00.01.1900 which would be an invalid time object, so take 31.12.1899 instead
569 1 my $date = localtime(timelocal_modern(0,0,0,31,11,1899) + $arg * 60 * 60 * 24 - 1);
570 # why subtract 1 before getting localtime for $date ? excel wrongly assumes 1900 is a leap year: https://learn.microsoft.com/en-us/office/troubleshoot/excel/wrongly-assumes-1900-is-leap-year
571 1 return sprintf("%04d%02d%02d",$date->year()+1900,$date->mon()+1,$date->mday());
572 }
573  
574 8 ▶sub skipOnDate ($$;$) {
Subroutine skipOnDate: called CC=29 SCAR=38.6
Pod documented
575 8 my ($onlyPassIf,$checkDate,$checkHoliday) = @_;
576 8 ▶ $checkHoliday = "AT" if !$checkHoliday;
Branch: 1 branch
BranchTrueFalseTotal
unless $checkHoliday 7 1 8
577 8 ▶ my $is_weekend = is_weekend($checkDate); $is_weekend = "" if !$is_weekend;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_weekend 6 2 8
578 8 ▶ my ($onlyPassIfCal, $checkCal) = ($onlyPassIf =~ /(..)(..)*/); $onlyPassIfCal = "" if !$onlyPassIfCal; $checkCal = "AT" if !$checkCal;
Branch: 2 branches
BranchTrueFalseTotal
unless $onlyPassIfCal 3 5 8
unless $checkCal 7 1 8
579 8 ▶ my $is_holiday = is_holiday($checkCal,$checkDate); $is_holiday = "" if !$is_holiday;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_holiday 6 2 8
580 8 ▶ my $is_last_day_of_month = is_last_day_of_month($checkDate,$checkCal); $is_last_day_of_month = "" if !$is_last_day_of_month;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_last_day_of_month 8 0 8
581  
582 8 ▶ if ($onlyPassIf eq "B" and ($is_weekend || $is_holiday)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($onlyPassIf eq "B" and $is_weekend || $is_holiday) 2 6 8
Condition50%3/6
$onlyPassIf eq "B" and $is_weekend || $is_holiday
!ll&&!rl&&r
602
$is_weekend or $is_holiday
l!l&&r!l&&!r
200
MC/DC33%1/3
$onlyPassIf eq "B" and $is_weekend || $is_holiday
$onlyPassIf eq "B" $is_weekend $is_holiday
Truth table50%2/4
A and B or C
A= $onlyPassIf eq "B"B= $is_weekendC= $is_holiday
ABCresult
0XX0
1000
11X1
1011
583 2 return "skipping as \$onlyPassIf eq B and is_weekend($checkDate)=".$is_weekend." || is_holiday(".$checkHoliday.",$checkDate)=".$is_holiday;
584 }
585 6 ▶ if ($onlyPassIf eq "M1" and $checkDate !~ /\d{4}\d{2}01/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($onlyPassIf eq "M1" and not $checkDate =~ /\d{4}\d{2}01/u) 1 5 6
Condition66%2/3
$onlyPassIf eq "M1" and not $checkDate =~ /\d{4}\d{2}01/u
!ll&&!rl&&r
501
MC/DC50%1/2
$onlyPassIf eq "M1" and not $checkDate =~ /\d{4}\d{2}01/u
$onlyPassIf eq "M1" not $checkDate =~ /\d{4}\d{2}01/u
Truth table66%2/3
A and not(B)
A= $onlyPassIf eq "M1"B= not $checkDate =~ /\d{4}\d{2}01/u
ABresult
0X0
100
111
586 1 return "skipping as \$onlyPassIf eq M1 and curDate ($checkDate) !~ /\\d{4}\\d{2}01/";
587 }
588 5 ▶ if ($onlyPassIf eq "Q" and $checkDate !~ /\d{4}010[12]/ and $checkDate !~ /\d{4}0401/ and $checkDate !~ /\d{4}0701/ and $checkDate !~ /\d{4}1001/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($onlyPassIf eq "Q" and not $checkDate =~ /\d{4}010[12]/u and not $checkDate =~ /\d{4}0401/u and not $checkDate =~ /\d{4}0701/u and not $checkDate =~ /\d{4}1001/u) 1 4 5
Condition66%8/12
$onlyPassIf eq "Q" and not $checkDate =~ /\d{4}010[12]/u and not $checkDate =~ /\d{4}0401/u and not $checkDate =~ /\d{4}0701/u and not $checkDate =~ /\d{4}1001/u
!ll&&!rl&&r
401
$onlyPassIf eq "Q" and not $checkDate =~ /\d{4}010[12]/u and not $checkDate =~ /\d{4}0401/u and not $checkDate =~ /\d{4}0701/u
!ll&&!rl&&r
401
$onlyPassIf eq "Q" and not $checkDate =~ /\d{4}010[12]/u and not $checkDate =~ /\d{4}0401/u
!ll&&!rl&&r
401
$onlyPassIf eq "Q" and not $checkDate =~ /\d{4}010[12]/u
!ll&&!rl&&r
401
MC/DC20%1/5
$onlyPassIf eq "Q" and not $checkDate =~ /\d{4}010[12]/u and not $checkDate =~ /\d{4}0401/u and not $checkDate =~ /\d{4}0701/u and not $checkDate =~ /\d{4}1001/u
$onlyPassIf eq "Q" not $checkDate =~ /\d{4}010[12]/u not $checkDate =~ /\d{4}0401/u not $checkDate =~ /\d{4}0701/u not $checkDate =~ /\d{4}1001/u
Truth table33%2/6
A and not(B) and not(C) and not(D) and not(E)
A= $onlyPassIf eq "Q"B= not $checkDate =~ /\d{4}010[12]/uC= not $checkDate =~ /\d{4}0401/uD= not $checkDate =~ /\d{4}0701/uE= not $checkDate =~ /\d{4}1001/u
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
589 1 return "skipping as \$onlyPassIf eq Q and curDate ($checkDate) !~ /\\d{4}0102/ and curDate !~ /\\d{4}0401/ and curDate !~ /\\d{4}0701/ and curDate !~ /\\d{4}1001/";
590 }
591 # skip if checkDate is not on the last day of month, or in case a calendar is given, on the last day of month regarding the calendar (in this case, skip also on weekends and holidays!)
592 4 ▶ if ($onlyPassIfCal eq "ML" and (!$is_last_day_of_month or ($checkCal and ($is_weekend or $is_holiday)))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($onlyPassIfCal eq "ML" and !$is_last_day_of_month || $checkCal && ($is_weekend || $is_holiday)) 2 2 4
Condition25%3/12
$onlyPassIfCal eq "ML" and !$is_last_day_of_month || $checkCal && ($is_weekend || $is_holiday)
!ll&&!rl&&r
202
not $is_last_day_of_month or $checkCal and $is_weekend || $is_holiday
l!l&&r!l&&!r
200
$checkCal and $is_weekend || $is_holiday
!ll&&!rl&&r
000
$is_weekend or $is_holiday
l!l&&r!l&&!r
000
MC/DC20%1/5
$onlyPassIfCal eq "ML" and !$is_last_day_of_month || $checkCal && ($is_weekend || $is_holiday)
$onlyPassIfCal eq "ML" not $is_last_day_of_month $checkCal $is_weekend $is_holiday
Truth table33%2/6
A and not(B) or C and D or E
A= $onlyPassIfCal eq "ML"B= not $is_last_day_of_monthC= $checkCalD= $is_weekendE= $is_holiday
ABCDEresult
0XXXX0
100XX0
101000
11XXX1
1011X1
101011
593 2 ▶ return "skipping as \$onlyPassIf eq ML".($checkCal ? $checkCal : "")." and (!is_last_day_of_month($checkDate".($checkCal ? ",$checkCal" : "").")=".$is_last_day_of_month." or (\$checkCal(=".($checkCal ? $checkCal : "").") and (is_weekend($checkDate)=".$is_weekend." or is_holiday($checkCal,$checkDate)=".$is_holiday."))))";
Branch: 3 branches
BranchTrueFalseTotal
$checkCal ? : 2 0 2
$checkCal ? : 2 0 2
$checkCal ? : 2 0 2
594 }
595 2 ▶ if (substr($onlyPassIf,0,1) eq "W" and !(weekday($checkDate) eq substr($onlyPassIf,1,1))) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($onlyPassIf, 0, 1) eq "W" and not &weekday($checkDate) eq substr($onlyPassIf, 1, 1)) 1 1 2
Condition66%2/3
substr($onlyPassIf, 0, 1) eq "W" and not &weekday($checkDate) eq substr($onlyPassIf, 1, 1)
!ll&&!rl&&r
101
MC/DC50%1/2
substr($onlyPassIf, 0, 1) eq "W" and not &weekday($checkDate) eq substr($onlyPassIf, 1, 1)
substr($onlyPassIf, 0, 1) eq "W" not &weekday($checkDate) eq substr($onlyPassIf, 1, 1)
Truth table66%2/3
A and not(B)
A= substr($onlyPassIf, 0, 1) eq "W"B= not &weekday($checkDate) eq substr($onlyPassIf, 1, 1)
ABresult
0X0
100
111
596 1 return "skipping as substr($onlyPassIf,0,1) eq W and !(weekday($checkDate) (".weekday($checkDate).") eq substr($onlyPassIf,1,1))";
597 }
598 1 ▶ if (substr($onlyPassIf,0,2) eq "MW" and !(first_weekYYYYMMDD($checkDate,substr($onlyPassIf,2,1)))) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($onlyPassIf, 0, 2) eq "MW" and not &first_weekYYYYMMDD($checkDate, substr($onlyPassIf, 2, 1))) 1 0 1
Condition33%1/3
substr($onlyPassIf, 0, 2) eq "MW" and not &first_weekYYYYMMDD($checkDate, substr($onlyPassIf, 2, 1))
!ll&&!rl&&r
001
MC/DC0%0/2
substr($onlyPassIf, 0, 2) eq "MW" and not &first_weekYYYYMMDD($checkDate, substr($onlyPassIf, 2, 1))
substr($onlyPassIf, 0, 2) eq "MW" not &first_weekYYYYMMDD($checkDate, substr($onlyPassIf, 2, 1))
Truth table33%1/3
A and not(B)
A= substr($onlyPassIf, 0, 2) eq "MW"B= not &first_weekYYYYMMDD($checkDate, substr($onlyPassIf, 2, 1))
ABresult
0X0
100
111
599 1 return "skipping as substr($onlyPassIf,0,2) eq MW and !(first_weekYYYYMMDD($checkDate,substr($onlyPassIf,2,1)))";
600 }
601 0 return "";
602 }
603  
604 6 1;
605 __END__
« Common.pm ↑ Summary checkLogExist.pl »