blib/lib/Date/Holidays/NZ.pm

filter: Statementstmt 97.4% 153 / 157 Branchbran 85.3% 70 / 82 Conditioncond 57.8% 22 / 38 MC/DCmcdc 28.5% 6 / 21 Subroutinesub 100% 17 / 17 Podpod 40.0% 4 / 10 totaltotal 83.6% 272 / 325 CC 59 SCAR 20.7
CC
59
Cov
88%
nz_holidays
13.1
nz_holiday_date
11.1
is_nz_holiday
10.8
CRAP 7.9
↑ Summary
1 package Date::Holidays::NZ;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use vars qw($VERSION @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $VERSION = '1.06';
8 1 @EXPORT = qw(is_nz_holiday nz_holidays nz_regional_day nz_holiday_date);
9 1 @EXPORT_OK = qw(%HOLIDAYS @NATIONAL_HOLIDAYS %regions
10 nz_region_code nz_region_name %holiday_cache);
11  
12 1 my $AD = "Anniversary Day";
13  
14 # Matariki dates 2022-2052 from
15 # https://www.mbie.govt.nz/assets/matariki-dates-2022-to-2052-matariki-advisory-group.pdf
16 1 our %MATARIKI = (
17 2022 => '2022-06-24',
18 2023 => '2023-07-14',
19 2024 => '2024-06-28',
20 2025 => '2025-06-20',
21 2026 => '2026-07-10',
22 2027 => '2027-06-25',
23 2028 => '2028-07-14',
24 2029 => '2029-07-06',
25 2030 => '2030-06-21',
26 2031 => '2031-07-11',
27 2032 => '2032-07-02',
28 2033 => '2033-06-24',
29 2034 => '2034-07-07',
30 2035 => '2035-06-29',
31 2036 => '2036-07-21',
32 2037 => '2037-07-10',
33 2038 => '2038-06-25',
34 2039 => '2039-07-15',
35 2040 => '2040-07-06',
36 2041 => '2041-07-19',
37 2042 => '2042-07-11',
38 2043 => '2043-07-03',
39 2044 => '2044-06-24',
40 2045 => '2045-07-07',
41 2046 => '2046-06-29',
42 2047 => '2047-07-19',
43 2048 => '2048-07-03',
44 2049 => '2049-06-25',
45 2050 => '2050-07-15',
46 2051 => '2051-06-30',
47 2052 => '2052-06-21'
48 );
49  
50 1 our %HOLIDAYS
51 = (
52 # Holidays which are fixed, but are moved to the next working
53 # day if you would not normally have worked on that day
54 "New Year's Day" => "0101+",
55 "Day after New Year's Day" => '0102+',
56 "Christmas Day" => "1225+",
57 "Boxing Day" => '1226+',
58 "Waitangi Day" => "0206+",
59 "Anzac Day" => "0425+",
60  
61 # Other national holidays
62 "Easter Monday" => "Easter + 1day",
63 "Good Friday" => "Easter - 2days",
64 "Queen's Birthday" => '1st Monday in June',
65 "Labour Day" => "4th Monday in October",
66 "Matariki" => "Matariki",
67  
68 # Anniversary days - these are the official dates, but regional
69 # authorities and sometimes district councils pick the actual dates.
70 "Auckland $AD" => "Closest Monday to 0129",
71  
72 # 2nd Monday in March to avoid Easter.
73 "Taranaki $AD" => "2nd Monday in March",
74  
75 # Moved to Friday before Labour Day.
76 "Hawke's Bay $AD" => "4th Monday in October - 3days",
77  
78 "Wellington $AD" => "Closest Monday to 0122",
79  
80 # "Marlborough $AD" => "Closest Monday to 1101",
81 # Observed 1st Monday after Labour Day.
82 "Marlborough $AD" => "4th Monday in October + 7days",
83  
84 "Nelson $AD" => "Closest Monday to 0201",
85  
86 "Westland $AD" => "Closest Monday to 1201",
87 # "Varies throughout Westland, but Greymouth observes the
88 # official day." - that's the West Coast for you
89  
90 # https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-and-anniversary-dates/ states: "there is no easily determined single day of local observance for Otago"
91 "Otago $AD" => "Closest Monday to 0323",
92  
93 # In 2011, the three southern mayors decided Southland Anniversary Day
94 # would be celebrated on Easter Tuesday.
95 "Southland $AD" => "Easter + 2days",
96  
97 "Chatham Islands $AD" => "Closest Monday to 1130",
98  
99 # South Canterbury observes Dominion Day
100 "Dominion Day" => "4th Monday in September",
101  
102 # North Canterbury observes Christchurch show day
103 # "2nd Friday after the first Tuesday in November"
104 "Christchurch Show Day" => "1st Tuesday in November + 10d",
105 );
106  
107 1 our %CHANGESET_2010 = (
108 # Pre-2011 dates for Southland
109 "Southland $AD" => "Closest Monday to 0117",
110 );
111  
112 1 our %CHANGESET_2014 = (
113 # Pre-mondayisation dates for Waitangi and Anzac days
114 "Waitangi Day" => "0206",
115 "Anzac Day" => "0425",
116 );
117  
118 1 our @NATIONAL_HOLIDAYS = ( "Waitangi Day",
119 "Anzac Day",
120 "New Year's Day",
121 "Day after New Year's Day",
122 "Christmas Day",
123 "Boxing Day",
124 "Easter Monday",
125 "Good Friday",
126 "Queen's Birthday",
127 "Labour Day",
128 );
129  
130 1 our @NATIONAL_HOLIDAYS_ADDED_2022 = ( "Matariki" );
131  
132 1 our %holiday_aliases =
133 ( "Birthday of the Reigning Sovereign" => "Queen's Birthday",
134 );
135  
136 # These are region codes from 2022 Regional Councils:
137 # https://datafinder.stats.govt.nz/layer/106666-regional-council-2022-generalised/data/
138 1 our %regions =
139 (
140 1 => "Northland",
141 2 => "Auckland",
142 3 => "Waikato",
143 4 => "Bay of Plenty",
144 5 => "Gisborne",
145 6 => "Hawke's Bay",
146 7 => "Taranaki",
147 8 => "Manawatū-Whanganui",
148 9 => "Wellington",
149 12 => "West Coast",
150 13 => "Canterbury",
151 -13 => "Canterbury (South)", # tsk! naughty use of sign bit
152 14 => "Otago",
153 15 => "Southland",
154 16 => "Tasman",
155 17 => "Nelson",
156 18 => "Marlborough",
157 99 => "Outside Regional Authority (incl. Chatham Is)",
158 );
159 1 our %rev_regions;
160  
161 # Some regions may be split in which Anniversary Day they follow, this has been updated
162 # using various government and web sources, including: Wikipedia and
163 # https://www.employment.govt.nz/leave-and-holidays/public-holidays/public-holidays-and-anniversary-dates/
164 1 our %FOLLOW = ( 1 => 2, 3 => 2, 4 => 2, 5 => 2,
165 8 => 9, 12 => "Westland",
166 13 => "Christchurch Show Day",
167 -13 => "Dominion Day",
168 16 => 17,
169 99 => "Chatham Islands",
170 );
171  
172 1 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
173 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
174  
175 36 ▶sub rev_regions {
Subroutine rev_regions: called CC=3 SCAR=11.0
Pod undocumented
176 36 my $region_name = shift;
177 36 ▶ unless ( $rev_regions{Auckland} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Date::Holidays::NZ::rev_regions{"Auckland"}) 36 0 36
178 36 %rev_regions = map { lc($_) } reverse %regions;
179 }
180 36 ▶ return $rev_regions{lc($region_name)}
Condition100%2/2
$Date::Holidays::NZ::rev_regions{lc $region_name} || croak("`${region_name}' is not a valid NZ region name")
l!l
333
MC/DC100%1/1
$Date::Holidays::NZ::rev_regions{lc $region_name} || croak("`${region_name}' is not a valid NZ region name")
$Date::Holidays::NZ::rev_regions{lc $region_name}
Truth table100%2/2
A
A= $Date::Holidays::NZ::rev_regions{lc $region_name}
Aresult
11
00
181 || croak "`$region_name' is not a valid NZ region name";
182 }
183  
184 10 ▶sub nz_region_name {
Subroutine nz_region_name: called CC=4 SCAR=13.9
Pod undocumented
185 10 my $region = shift;
186 10 ▶ return undef unless defined $region;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $region 0 10 10
187 10 ▶ if ( looks_like_number($region) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($region)) { } 6 4 10
188 6 ▶ return $regions{$region}
Condition100%2/2
$Date::Holidays::NZ::regions{$region} || croak("no such NZ region code `${region}'")
l!l
51
MC/DC0%0/1
$Date::Holidays::NZ::regions{$region} || croak("no such NZ region code `${region}'")
$Date::Holidays::NZ::regions{$region}
Truth table50%1/2
A
A= $Date::Holidays::NZ::regions{$region}
Aresult
11
00
189 || croak "no such NZ region code `$region'";
190 } else {
191 4 return $regions{rev_regions($region)};
192 }
193 }
194  
195 34 ▶sub nz_region_code {
Subroutine nz_region_code: called CC=4 SCAR=13.9
Pod undocumented
196 34 my $region = shift;
197 34 ▶ return undef unless defined $region;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $region 0 34 34
198 34 ▶ if ( looks_like_number($region) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($region)) { } 5 29 34
199 5 ▶ exists $regions{$region}
Branch: 1 branch
BranchTrueFalseTotal
exists $Date::Holidays::NZ::regions{$region} or croak("no such NZ region code `${region}'") 4 1 5
200 or croak "no such NZ region code `$region'";
201 4 return $region;
202 } else {
203 29 return rev_regions($region);
204 }
205 }
206  
207 # try to guess the regional day observed from the region
208 93 ▶sub nz_regional_day {
Subroutine nz_regional_day: called CC=7 SCAR=19.5
Pod documented
209 93 ▶ my $label = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $label = shift() or return undef 93 0 93
210  
211 93 ▶ if ( !looks_like_number($label) and
Branch: 1 branch
BranchTrueFalseTotal
if (not &looks_like_number($label) and exists $Date::Holidays::NZ::HOLIDAYS{$label . " $AD"}) 65 28 93
Condition100%3/3
not &looks_like_number($label) and exists $Date::Holidays::NZ::HOLIDAYS{$label . " $AD"}
!ll&&!rl&&r
32565
MC/DC100%2/2
not &looks_like_number($label) and exists $Date::Holidays::NZ::HOLIDAYS{$label . " $AD"}
not &looks_like_number($label) exists $Date::Holidays::NZ::HOLIDAYS{$label . " $AD"}
Truth table100%3/3
not(A) and B
A= not &looks_like_number($label)B= exists $Date::Holidays::NZ::HOLIDAYS{$label . " $AD"}
ABresult
0X0
100
111
212 exists $HOLIDAYS{$label." $AD"} ) {
213 65 return "$label $AD";
214 }
215 28 my $region = nz_region_code($label);
216 28 my $followed;
217 28 ▶ if ( $followed = $FOLLOW{$region} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($followed = $Date::Holidays::NZ::FOLLOW{$region}) { } 27 1 28
218 27 ▶ if ( looks_like_number($followed) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($followed)) 3 24 27
219 3 $followed = nz_region_name($followed);
220 }
221 }
222 else {
223 1 $followed = nz_region_name($region);
224 }
225 28 ▶ if ( $followed !~ /Day$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($followed =~ /Day$/) 12 16 28
226 12 $followed .= " $AD";
227 }
228 28 return $followed;
229 }
230  
231 158 ▶sub check_falling_on {
Subroutine check_falling_on: called CC=5 SCAR=16.1
Pod undocumented
232 158 my ($h, $year, $date) = @_;
233  
234 158 my $falls_on = UnixDate($year.$date, "%w");
235 158 ▶ if ( $falls_on >= 6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($falls_on >= 6) 42 116 158
236 42 my $name = delete $h->{$date};
237 42 ▶ my $add = ($falls_on == 6) ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$falls_on == 6 ? : 22 20 42
238 42 my $to_fall_on = UnixDate(DateCalc($year.$date, "+${add}d"), "%m%d");
239 42 ▶ while ( exists $h->{$to_fall_on} or
Branch: 1 branch
BranchTrueFalseTotal
if (exists $h->{$to_fall_on} or UnixDate($year . $to_fall_on, "%w") >= 6) 16 42 58
Condition66%2/3
exists $h->{$to_fall_on} or UnixDate($year . $to_fall_on, "%w") >= 6
l!l&&r!l&&!r
16042
MC/DC50%1/2
exists $h->{$to_fall_on} or UnixDate($year . $to_fall_on, "%w") >= 6
exists $h->{$to_fall_on} UnixDate($year . $to_fall_on, "%w") >= 6
Truth table66%2/3
A or B
A= exists $h->{$to_fall_on}B= UnixDate($year . $to_fall_on, "%w") >= 6
ABresult
1X1
011
000
240 UnixDate($year.$to_fall_on, "%w") >= 6
241 ) {
242 16 $to_fall_on = UnixDate(DateCalc($year.$to_fall_on, "+1d"), "%m%d");
243 }
244 42 $h->{$to_fall_on} = "$name Holiday";
245 }
246 }
247  
248 1 ▶use Date::Manip qw(DateCalc ParseDate UnixDate ParseRecur);
Subroutine BEGIN: called CC=1 SCAR=0.0
249  
250 456 ▶sub interpret_date {
Subroutine interpret_date: called CC=9 SCAR=22.0
Pod undocumented
251 456 my $year = shift;
252 456 my $value = shift;
253  
254 456 my ($date, $add);
255 456 ▶ if ( $value =~ m/^(\d\d)(\d\d)\+?$/ ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($value =~ /^(\d\d)(\d\d)\+?$/) { } 193 263 456
elsif ($value =~ /^(\d+(?:st|nd|rd|th) \w+day in \w+)(.*)$/i) { } 113 150 263
elsif ($value =~ /^Closest (\w+day) to (\d\d)(\d\d)(.*)$/i) { } 67 83 150
elsif ($value =~ /^Easter(.*)$/i) { } 70 13 83
elsif ($value =~ /^Matariki$/i) { } 13 0 13
256 193 return $value;
257 }
258 elsif ( $value =~ m/^(\d+(?:st|nd|rd|th) \w+day in \w+)(.*)$/i) {
259 113 (my $spec, $add) = ($1, $2);
260 113 $date = ParseDate($spec. " $year");
261 }
262 elsif ( $value =~ m/^Closest (\w+day) to (\d\d)(\d\d)(.*)$/i) {
263 67 (my ($day, $month, $dom), $add) = ($1, $2, $3, $4);
264 67 $date = ParseDate("$year-$month-$dom");
265 67 my $wanted = UnixDate($day, "%w");
266 67 my $got = UnixDate($date, "%w");
267 67 ▶ if ( my $diff = ($wanted - $got + 7) % 7 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $diff = ($wanted - $got + 7) % 7) 59 8 67
268 59 ▶ if ( $diff < 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diff < 4) { } 27 32 59
269 27 $date = DateCalc($date, "+${diff}d");
270 } else {
271 32 $diff = 7 - $diff;
272 32 $date = DateCalc($date, "-${diff}d");
273 }
274 }
275 }
276 elsif ( $value =~ m/^Easter(.*)$/i) {
277 70 ($date) = ParseRecur("*$year:0:0:0:0:0:0*EASTER");
278 70 $add = $1;
279 }
280 elsif ( $value =~ m/^Matariki$/i) {
281 # return a date for Matariki if one is available for the year
282 13 ($date) = ParseDate($MATARIKI{$year});
283 }
284 263 ▶ $date = DateCalc($date, "$add") if $add;
Branch: 1 branch
BranchTrueFalseTotal
if $add 97 166 263
285 263 return UnixDate($date, "%m%d");
286 }
287  
288 30 ▶sub nz_stat_holidays {
Subroutine nz_stat_holidays: called CC=9 SCAR=22.0
Pod undocumented
289 30 my $year = shift;
290  
291 30 my %holidays = %HOLIDAYS;
292  
293 30 ▶ if ( $year < 2011 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($year < 2011) 8 22 30
294 8 %holidays = ( %holidays, %CHANGESET_2010 );
295 }
296  
297 # merge the old definitions of Waitangi day and Anzac day if year is pre-mondayisation
298 30 ▶ if ( $year < 2014 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($year < 2014) 11 19 30
299 11 %holidays = ( %holidays, %CHANGESET_2014 );
300 }
301  
302 30 my @national_holidays = @NATIONAL_HOLIDAYS;
303 30 ▶ if ( $year >= 2022 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($year >= 2022) 11 19 30
304 11 push(@national_holidays, @NATIONAL_HOLIDAYS_ADDED_2022);
305 }
306  
307 # build the relative dates
308 30 my (%h, @tentative);
309 30 foreach my $holiday (@national_holidays) {
310  
311 311 ▶ my $when = interpret_date($year, $holidays{$holiday}||die)
Branch: 1 branch
BranchTrueFalseTotal
my $when = interpret_date($year, $holidays{$holiday} || die()) or die "couldn't interpret $year, $holidays{$holiday}" 311 0 311
Condition50%1/2
$holidays{$holiday} || die()
l!l
3110
MC/DC0%0/1
$holidays{$holiday} || die()
$holidays{$holiday}
Truth table50%1/2
A
A= $holidays{$holiday}
Aresult
11
00
312 or die "couldn't interpret $year, $holidays{$holiday}";
313  
314 311 ▶ if ( $when =~ s/\+// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($when =~ s/\+//) 158 153 311
315 158 push @tentative, $when;
316 }
317 311 $h{$when} = $holiday;
318 }
319 30 for my $date ( sort { $a <=> $b } @tentative ) {
320 158 check_falling_on(\%h, $year, $date);
321 }
322  
323 30 return \%h;
324 }
325  
326 1 our %regional_holiday_cache
327 = # exceptions
328 ( "2004/Westland $AD" => "1129",
329 "2008/Otago $AD" => "0325",
330 );
331  
332 1 our %holiday_cache;
333  
334 139 ▶sub nz_holidays {
Subroutine nz_holidays: called CC=7 SCAR=25.7
Pod documented
335 139 my ($year, $region) = @_;
336  
337 139 ▶ my $hols = $holiday_cache{$year} ||= nz_stat_holidays($year);
Condition66%2/3
$Date::Holidays::NZ::holiday_cache{$year} ||= nz_stat_holidays($year)
l!l&&r!l&&!r
109300
MC/DC0%0/2
$Date::Holidays::NZ::holiday_cache{$year} ||= nz_stat_holidays($year)
$Date::Holidays::NZ::holiday_cache{$year} nz_stat_holidays($year)
Truth table66%2/3
A ||= B
A= $Date::Holidays::NZ::holiday_cache{$year}B= nz_stat_holidays($year)
ABresult
1X1
011
000
338  
339 139 my %holidays = %HOLIDAYS;
340 139 ▶ if ( $year < 2011 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($year < 2011) 80 59 139
341 80 %holidays = ( %holidays, %CHANGESET_2010 );
342 }
343  
344 139 ▶ if ( $region ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($region) 0 139 139
345 0 my $rd = nz_regional_day($region);
346  
347 my $when = $regional_holiday_cache{"$year/$rd"} ||=
348 0 ▶ (interpret_date($year, $holidays{$rd}||die)
Condition0%0/7
$Date::Holidays::NZ::regional_holiday_cache{"$year/$rd"} ||= interpret_date($year, $holidays{$rd} || die()) || die("couldn't interpret $year, $holidays{$rd}")
l!l&&r!l&&!r
000
interpret_date($year, $holidays{$rd} || die()) || die("couldn't interpret $year, $holidays{$rd}")
l!l
00
$holidays{$rd} || die()
l!l
00
MC/DC0%0/2
$Date::Holidays::NZ::regional_holiday_cache{"$year/$rd"} ||= interpret_date($year, $holidays{$rd} || die()) || die("couldn't interpret $year, $holidays{$rd}")
$Date::Holidays::NZ::regional_holiday_cache{"$year/$rd"} interpret_date($year, $holidays{$rd} || die())
MC/DC0%0/1
$holidays{$rd} || die()
$holidays{$rd}
Truth table0%0/3
A ||= B
A= $Date::Holidays::NZ::regional_holiday_cache{"$year/$rd"}B= interpret_date($year, $holidays{$rd} || die())
ABresult
1X1
011
000
Truth table0%0/2
A
A= $holidays{$rd}
Aresult
11
00
349 or die "couldn't interpret $year, $holidays{$rd}");
350  
351 0 $hols = { %$hols, $when => "$rd" };
352 }
353  
354 139 return $hols;
355 }
356  
357 168 ▶sub is_nz_holiday {
Subroutine is_nz_holiday: called CC=9 SCAR=23.8
Pod documented
358 168 my ($year, $month, $day, $region) = @_;
359 168 my $mmdd = sprintf("%.2d%.2d", $month, $day);
360  
361 168 my %holidays = %HOLIDAYS;
362 168 ▶ if ( $year < 2011 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($year < 2011) 168 0 168
363 168 %holidays = ( %holidays, %CHANGESET_2010 );
364 }
365  
366 168 ▶ my $hols = $holiday_cache{$year} ||= nz_stat_holidays($year);
Condition33%1/3
$Date::Holidays::NZ::holiday_cache{$year} ||= nz_stat_holidays($year)
l!l&&r!l&&!r
16800
MC/DC0%0/2
$Date::Holidays::NZ::holiday_cache{$year} ||= nz_stat_holidays($year)
$Date::Holidays::NZ::holiday_cache{$year} nz_stat_holidays($year)
Truth table33%1/3
A ||= B
A= $Date::Holidays::NZ::holiday_cache{$year}B= nz_stat_holidays($year)
ABresult
1X1
011
000
367  
368 168 ▶ if ( exists $hols->{$mmdd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hols->{$mmdd}) 0 168 168
369 0 return $hols->{$mmdd};
370 }
371  
372 168 ▶ if ( $region ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($region) 84 84 168
373 84 my $rd = nz_regional_day($region);
374  
375 my $when = $regional_holiday_cache{"$year/$rd"} ||=
376 84 ▶ (interpret_date($year, $holidays{$rd}||die)
Condition57%4/7
$Date::Holidays::NZ::regional_holiday_cache{"$year/$rd"} ||= interpret_date($year, $holidays{$rd} || die()) || die("couldn't interpret $year, $holidays{$rd}")
l!l&&r!l&&!r
2820
interpret_date($year, $holidays{$rd} || die()) || die("couldn't interpret $year, $holidays{$rd}")
l!l
820
$holidays{$rd} || die()
l!l
820
MC/DC0%0/2
$Date::Holidays::NZ::regional_holiday_cache{"$year/$rd"} ||= interpret_date($year, $holidays{$rd} || die()) || die("couldn't interpret $year, $holidays{$rd}")
$Date::Holidays::NZ::regional_holiday_cache{"$year/$rd"} interpret_date($year, $holidays{$rd} || die())
MC/DC0%0/1
$holidays{$rd} || die()
$holidays{$rd}
Truth table66%2/3
A ||= B
A= $Date::Holidays::NZ::regional_holiday_cache{"$year/$rd"}B= interpret_date($year, $holidays{$rd} || die())
ABresult
1X1
011
000
Truth table50%1/2
A
A= $holidays{$rd}
Aresult
11
00
377 or die "couldn't interpret $year, $holidays{$rd}");
378  
379 84 ▶ if ( $when eq $mmdd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($when eq $mmdd) 84 0 84
380 84 return $rd;
381 }
382 }
383  
384 84 return undef;
385 }
386  
387 52 ▶sub nz_holiday_date {
Subroutine nz_holiday_date: called CC=11 SCAR=24.0
Pod documented
388 52 my ($year, $holname) = @_;
389 52 ▶ $holname = $holiday_aliases{$holname} if $holiday_aliases{$holname};
Branch: 1 branch
BranchTrueFalseTotal
if $Date::Holidays::NZ::holiday_aliases{$holname} 1 51 52
390  
391 # merge the old definitions of Waitangi day and Anzac day if year is pre-mondayisation
392 52 my %holidays = %HOLIDAYS;
393 52 ▶ if ( $year < 2014 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($year < 2014) 4 48 52
394 4 %holidays = ( %holidays, %CHANGESET_2014 );
395 }
396  
397 52 my @national_holidays = @NATIONAL_HOLIDAYS;
398 # include Matariki from 2022
399 52 ▶ if ( $year >= 2022 ){
Branch: 1 branch
BranchTrueFalseTotal
if ($year >= 2022) 48 4 52
400 48 push(@national_holidays, @NATIONAL_HOLIDAYS_ADDED_2022);
401 }
402  
403 52 ▶ exists $holidays{$holname} or croak "no such holiday $holname";
Branch: 1 branch
BranchTrueFalseTotal
exists $holidays{$holname} or croak("no such holiday $holname") 52 0 52
404  
405 52 ▶ if ( grep $_ eq $holname, @national_holidays ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep(($_ eq $holname), @national_holidays)) { } 25 27 52
406  
407 25 my $date = interpret_date($year, $holidays{$holname});
408 25 my $hols = nz_holidays($year);
409  
410 25 ▶ if ( $date =~ s/\+$// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date =~ s/\+$//) 13 12 25
411 13 ▶ while ( not exists $hols->{$date} or
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $hols->{$date} and $hols->{$date} =~ /^\Q$holname\E/i) 11 13 24
Condition100%3/3
exists $hols->{$date} and $hols->{$date} =~ /^\Q$holname\E/i
!ll&&!rl&&r
8313
MC/DC100%2/2
exists $hols->{$date} and $hols->{$date} =~ /^\Q$holname\E/i
exists $hols->{$date} $hols->{$date} =~ /^\Q$holname\E/i
Truth table100%3/3
A and B
A= exists $hols->{$date}B= $hols->{$date} =~ /^\Q$holname\E/i
ABresult
0X0
100
111
412 $hols->{$date} !~ m/^\Q$holname\E/i
413 ) {
414 11 ▶ die "couldn't find it!" if $date eq "1231";
Branch: 1 branch
BranchTrueFalseTotal
if $date eq 1231 0 11 11
415 11 $date = UnixDate(DateCalc($year.$date, "+1d"), "%m%d");
416 }
417 }
418  
419 25 return $date;
420 } else {
421 return $regional_holiday_cache{"$year/$holname"}
422 27 ▶ || interpret_date($year, $holidays{$holname});
Condition66%2/3
$Date::Holidays::NZ::regional_holiday_cache{"$year/$holname"} || interpret_date($year, $holidays{$holname})
l!l&&r!l&&!r
2250
MC/DC0%0/2
$Date::Holidays::NZ::regional_holiday_cache{"$year/$holname"} || interpret_date($year, $holidays{$holname})
$Date::Holidays::NZ::regional_holiday_cache{"$year/$holname"} interpret_date($year, $holidays{$holname})
Truth table66%2/3
A || B
A= $Date::Holidays::NZ::regional_holiday_cache{"$year/$holname"}B= interpret_date($year, $holidays{$holname})
ABresult
1X1
011
000
423 }
424 }
425  
426 1 1;
427  
428 __END__
↑ Summary