blib/lib/Date/Holidays/CZ.pm

filter: Statementstmt 93.6% 59 / 63 Branchbran 50.0% 3 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 85.7% 72 / 84 CC 7 SCAR 13.9
CC
7
Cov
86%
holidays
7.5
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
↑ Summary
1 package Date::Holidays::CZ;
2  
3 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Date::Calc 5.0 qw(Add_Delta_Days Easter_Sunday Day_of_Week This_Year);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =encoding utf8
14  
15 =head1 NAME
16  
17 Date::Holidays::CZ - Determine Czech holidays
18  
19  
20  
21 =head1 SYNOPSIS
22  
23 use Date::Holidays::CZ qw(holidays);
24 my $svatky_ref = holidays();
25 my @svatky = @$svatky_ref;
26  
27  
28  
29 =head1 DESCRIPTION
30  
31 This module exports a single function named B<holidays()> which returns a list of
32 Czech holidays in a given year.
33  
34 =cut
35  
36 2 our @EXPORT_OK = qw( holidays );
37  
38  
39  
40 =head1 VERSION
41  
42 Version 0.20
43  
44 =cut
45  
46 2 our $VERSION = '0.20';
47  
48  
49  
50 =head1 KNOWN HOLIDAYS
51  
52 =head2 Czech names
53  
54 The module knows about the following holidays (official names):
55  
56 obss Den obnovy samostatného českého státu
57 velk Velikonoční pátek
58 veln Velikonoční neděle
59 velp Velikonoční pondělí
60 svpr Svátek práce
61 devi Den vítězství
62 cyme Den slovanských věrozvěstů Cyrila a Metoděje
63 mhus Den upálení mistra Jana Husa
64 wenc Den české státnosti
65 vzcs Den vzniku samostatného československého státu
66 bojs Den boje za svobodu a demokracii
67 sted Štědrý den
68 van1 1. svátek vánoční
69 van2 2. svátek vánoční
70  
71 =head2 English names
72  
73 The module knows about the following holidays (English names):
74  
75 obss Restoration Day of the Independent Czech State
76 velk Good Friday
77 veln Easter Sunday
78 velp Easter Monday
79 svpr Labor Day
80 dvit Liberation Day
81 cyme Saints Cyril and Methodius Day
82 mhus Jan Hus Day
83 wenc Feast of St. Wenceslas (Czech Statehood Day)
84 vzcs Independent Czechoslovak State Day
85 bojs Struggle for Freedom and Democracy Day
86 sted Christmas Eve
87 van1 Christmas Day
88 van2 Feast of St. Stephen
89  
90  
91  
92 =head1 USAGE
93  
94 =head2 OUTPUT FORMAT
95  
96 The list returned by B<holidays()> consists of UNIX-Style timestamps in seconds
97 since The Epoch. You may pass a B<strftime()> style format string to get the
98 dates in any format you desire:
99  
100 my $svatky_ref = holidays(FORMAT=>"%d.%m.%Y");
101  
102 Here are a few examples to get you started:
103  
104 FORMAT=>"%d.%m.%Y" 25.12.2001
105 FORMAT=>"%Y%m%d" 20011225
106 FORMAT=>"%a, %B %d" Tuesday, December 25
107  
108 Please consult the manual page of B<strftime()> for a complete list of available
109 format definitions.
110  
111 There is, however, one "proprietary" extension to the formats of B<strftime()>:
112 The format definition I<%#> will print the internal abbreviation used for each
113 holiday.
114  
115 FORMAT=>"%#: %d.%m" van1: 25.12.
116  
117 As the module doesn't want to deal with i18n
118 issues, you'll have to find your own way to translate the aliases into your
119 local language. See the I<example/svatky.pl> script included in the
120 distribution to get the idea.
121  
122  
123  
124 =head2 SPECIFYING THE YEAR
125  
126 By default, B<holidays()> returns the holidays for the current year. Specify
127 a year as follows:
128  
129 my $svatky_ref = holidays(YEAR=>2004);
130  
131  
132  
133 =head2 HOLIDAYS ON WEEKENDS
134  
135 By default, B<holidays()> includes Holidays that occur on weekends in its
136 listing.
137  
138 To disable this behaviour, set the I<WEEKENDS> option to 0:
139  
140 my $svatky_ref = holidays(WEEKENDS=>0);
141  
142  
143  
144 =head1 COMPLETE EXAMPLE
145  
146 Get all holidays in 2004, except those that occur on weekends.
147 Return the date list in human readable format:
148  
149 my $svatky_ref = holidays( FORMAT => "%a, %d.%m.%Y",
150 WEEKENDS => 0,
151 YEAR => 2004,
152 );
153  
154  
155 =head1 PREREQUISITES
156  
157 Uses L<Date::Calc> for all calculations. Makes use of the L<POSIX> and
158 L<Time::Local> modules from the standard Perl distribution.
159  
160  
161 =head1 FUNCTIONS
162  
163  
164 =head2 holidays
165  
166 Returns a list of Czech holidays in a given year.
167  
168 =cut
169  
170 2 ▶sub holidays{
Subroutine holidays: called CC=7 SCAR=20.2
Pod documented
171 2 my %parameters = (
172 YEAR => This_Year(),
173 FORMAT => "%s",
174 WEEKENDS => 1,
175 @_,
176 );
177  
178 # Easter is the key to everything
179 2 my ($year, $month, $day) = Easter_Sunday($parameters{'YEAR'});
180  
181 # Aliases for holidays
182 #
183 # obss Restoration Day of the Independent Czech State
184 # velk Good Friday
185 # veln Easter Sunday
186 # velp Easter Monday
187 # svpr Labor Day
188 # dvit Liberation Day
189 # cyme Saints Cyril and Methodius Day
190 # mhus Jan Hus Day
191 # wenc Feast of St. Wenceslas (Czech Statehood Day)
192 # vzcs Independent Czechoslovak State Day
193 # bojs Struggle for Freedom and Democracy Day
194 # sted Christmas Eve
195 # van1 Christmas Day
196 # van2 Feast of St. Stephen
197 #
198  
199 #
200 # Sort out who has which holidays
201 #
202 2 my %holidays;
203 # Common holidays throughout the Czech Republic
204 2 @{$holidays{'common'}} = qw( obss velk veln velp svpr dvit
205 cyme mhus wenc vzcs bojs sted van1 van2 );
206  
207 #
208 # Fixed-date holidays
209 #
210 2 my %holiday;
211 # Jan 1
212 2 $holiday{'obss'} = _date2timestamp($year, 1, 1);
213  
214 # May 1
215 2 $holiday{'svpr'} = _date2timestamp($year, 5, 1);
216  
217 # Liberation Day
218 2 $holiday{'dvit'} = _date2timestamp($year, 5, 8);
219  
220 # Saints Cyril and Methodius Day
221 2 $holiday{'cyme'} = _date2timestamp($year, 7, 5);
222  
223 # Jan Hus Day
224 2 $holiday{'mhus'} = _date2timestamp($year, 7, 6);
225  
226 # Feast of St. Wenceslas (Czech Statehood Day)
227 2 $holiday{'wenc'} = _date2timestamp($year, 9, 28);
228  
229 # Independent Czechoslovak State Day
230 2 $holiday{'vzcs'} = _date2timestamp($year, 10, 28);
231  
232 # Struggle for Freedom and Democracy Day
233 2 $holiday{'bojs'} = _date2timestamp($year, 11, 17);
234  
235 # Christmas eve and Christmas Dec 25-26
236 2 $holiday{'sted'} = _date2timestamp($year, 12, 24);
237 2 $holiday{'van1'} = _date2timestamp($year, 12, 25);
238 2 $holiday{'van2'} = _date2timestamp($year, 12, 26);
239  
240 #
241 # Holidays relative to Easter
242 #
243  
244 # Easter Sunday is just that
245 2 $holiday{'veln'} = _date2timestamp($year, $month, $day);
246  
247 # Easter Monday = Easter Sunday plus 1 day
248 2 my ($y_velp, $m_velp, $d_velp) =
249 Date::Calc::Add_Delta_Days($year, $month, $day, 1);
250 2 $holiday{'velp'} = _date2timestamp($y_velp, $m_velp, $d_velp);
251  
252 # Good Friday = Easter Sunday minus 2 days
253 2 ▶ if ($year >= 2016) {
Branch: 1 branch
BranchTrueFalseTotal
if ($year >= 2016) 1 1 2
254 1 my ($y_velk, $m_velk, $d_velk) =
255 Date::Calc::Add_Delta_Days($year, $month, $day, -2);
256 1 $holiday{'velk'} = _date2timestamp($y_velk, $m_velk, $d_velk);
257 }
258  
259 #
260 # Build list for returning
261 #
262 2 my %holidaylist = %holiday;
263  
264 #
265 # If WEEKENDS => 0 was passed, weed out holidays on weekends
266 #
267 2 ▶ unless (1 == $parameters{'WEEKENDS'}){
Branch: 1 branch
BranchTrueFalseTotal
unless (1 == $parameters{"WEEKENDS"}) 0 2 2
268 # Walk the list of holidays
269 0 foreach my $alias(keys(%holidaylist)){
270 # Get day of week. Since we're no longer
271 # in Date::Calc's world, use localtime()
272 0 my $dow = (localtime($holiday{$alias}))[6];
273 # dow 6 = Saturday, dow 0 = Sunday
274 0 ▶ if ((6 == $dow) or (0 == $dow)){
Branch: 1 branch
BranchTrueFalseTotal
if (6 == $dow or 0 == $dow) 0 0 0
Condition0%0/3
6 == $dow or 0 == $dow
l!l&&r!l&&!r
000
MC/DC0%0/2
6 == $dow or 0 == $dow
6 == $dow 0 == $dow
Truth table0%0/3
A or B
A= 6 == $dowB= 0 == $dow
ABresult
1X1
011
000
275 # Kick this day from the list
276 0 delete $holidaylist{$alias};
277 }
278 }
279 }
280  
281 #
282 # Sort values stored in the hash for returning
283 #
284 2 my @returnlist;
285 2 foreach(sort{$holidaylist{$a}<=>$holidaylist{$b}}(keys(%holidaylist))){
286 # Not all platforms have strftime(%s).
287 # Therefore, inject seconds manually into format string.
288 27 my $formatstring = $parameters{'FORMAT'};
289 27 $formatstring =~ s/%{0}%s/$holidaylist{$_}/g;
290 # Inject the holiday's alias name into the format string
291 # if it was requested by adding %#.
292 27 $formatstring =~ s/%{0}%#/$_/;
293 push @returnlist,
294 27 strftime($formatstring, localtime($holidaylist{$_}));
295 }
296 2 return \@returnlist;
297 }
298  
299 27 ▶sub _date2timestamp{
Subroutine _date2timestamp: called CC=1 SCAR=0.0
300 # Turn Date::Calc's y/m/d format into a UNIX timestamp
301 27 my ($y, $m, $d) = @_;
302 27 my $timestamp = timelocal(0,0,0,$d,($m-1),$y);
303 27 return $timestamp;
304 }
305  
306  
307 =head1 BUGS & SUGGESTIONS
308  
309 If you run into a miscalculation, need some sort of feature or an additional
310 holiday, or if you know of any new changes to our funky holiday situation,
311 please drop the author a note.
312  
313 Patches are welcome. If you can, please fork the project on I<github> to
314 submit your change:
315  
316 http://github.com/smithfarm/Date-Holidays-CZ
317  
318  
319  
320 =head1 OFFICIAL HOLIDAY INFORMATION
321  
322 The authority for Czech holidays is the Parliament of the Czech Republic,
323 which sets the holidays by decree of law.
324  
325 The official list of list of Czech holidays is available at:
326  
327 http://www.mpsv.cz/cs/74
328  
329  
330  
331 =head1 LIMITATIONS
332  
333 B<Date::Calc> works with year, month and day numbers exclusively. Even though
334 this module uses B<Date::Calc> for all calculations, it represents the calculated
335 holidays as UNIX timestamps (seconds since The Epoch) to allow for more
336 flexible formatting. This limits the range of years to work on to
337 the years from 1972 to 2037.
338  
339 B<Date::Holidays::CZ> is not configurable. Holiday changes don't come overnight
340 and a new module release can be rolled out within a single day.
341  
342  
343  
344 =head1 AUTHOR
345  
346 Nathan Cutler <ncutler@suse.com>
347  
348  
349  
350 =head1 LICENSE
351  
352 The code in this module is based heavily on Date::Holidays::DE version 0.16 by
353 Martin Schmitt. That code is governed by the following license:
354  
355 Copyright (c) 2012, Martin Schmitt <mas at scsy dot de>,
356 including patches contributed by Marc Andre Selig, Oliver Paukstadt,
357 Tobias Leich and Christian Loos
358
359 Permission to use, copy, modify, and/or distribute this software for any
360 purpose with or without fee is hereby granted, provided that the above
361 copyright notice and this permission notice appear in all copies.
362
363 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
364 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
365 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
366 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
367 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
368 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
369 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
370  
371 All modifications to the original Date::Holidays::DE code, as well as all new
372 code, are governed by the following:
373  
374 Copyright (c) 2015-2020, SUSE LLC
375 All rights reserved.
376
377 This is free software, licensed under:
378
379 The (three-clause) BSD License
380
381 The BSD License
382
383 Redistribution and use in source and binary forms, with or without
384 modification, are permitted provided that the following conditions are
385 met:
386
387 * Redistributions of source code must retain the above copyright
388 notice, this list of conditions and the following disclaimer.
389
390 * Redistributions in binary form must reproduce the above copyright
391 notice, this list of conditions and the following disclaimer in the
392 documentation and/or other materials provided with the distribution.
393
394 * Neither the name of SUSE LLC nor the names of its contributors may
395 be used to endorse or promote products derived from this software
396 without specific prior written permission.
397
398 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
399 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
400 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
401 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
402 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
403 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
404 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
405 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
406 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
407 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
408 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
409  
410  
411  
412 =head1 SEE ALSO
413  
414 L<perl>, L<Date::Calc>.
415  
416 =cut
417  
418 2 1;
↑ Summary