blib/lib/Date/Holidays/SK.pm

filter: Statementstmt 92.4% 49 / 53 Branchbran 90.9% 20 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 3 / 3 totaltotal 91.8% 79 / 86 CC 13 SCAR 18.2
CC
13
Cov
92%
sk_holidays
10.0
is_sk_holiday
4.0
is_sk_holiday_today
2.0
CRAP 6.2
↑ Summary
1 package Date::Holidays::SK;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.02';
7  
8 1 ▶use Date::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Date::Easter;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 our @EXPORT_OK = qw(
13 is_sk_holiday
14 is_sk_holiday_today
15 sk_holidays
16 );
17  
18 # Fixed-date holidays {'MMDD' => 'NAME'}
19 1 my $FIX = {
20 '0101' => 'Deň vzniku Slovenskej republiky',
21 '0106' => 'Zjavenie Pána (Traja králi)',
22 '0501' => 'Sviatok práce',
23 '0508' => 'Deň víťazstva nad fašizmom',
24 '0705' => 'Sviatok svätého Cyrila a Metoda',
25 '0829' => 'Výročie SNP',
26 '0901' => 'Deň Ústavy Slovenskej republiky',
27 '0915' => 'Sedembolestná Panna Mária',
28 '1101' => 'Sviatok všetkých svätých',
29 '1117' => 'Deň boja za slobodu a demokraciu',
30 '1224' => 'Štedrý deň',
31 '1225' => 'Prvý sviatok vianočný',
32 '1226' => 'Druhý sviatok vianočný',
33 };
34  
35 # The only variable-date holiday is Easter Monday and Easter Friday -- we deal with that separately
36 1 my $EF = 'Veľkonočný piatok';
37 1 my $EM = 'Veľkonočný pondelok';
38  
39 4 ▶sub is_sk_holiday {
Subroutine is_sk_holiday: called CC=4 SCAR=13.9
Pod documented
40 4 my ($year, $month, $day) = @_;
41  
42 4 my $k = sprintf "%02d%02d", $month, $day;
43  
44 # for fixed dates
45 return $FIX->{$k}
46 4 ▶ if exists $FIX->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $FIX->{$k} 1 3 4
47  
48 3 my $diff = Date::Simple->new($year, $month, $day) - Date::Simple->new($year, easter($year));
49 # Easter Sunday +1 -> Easter Monday.
50 3 ▶ return $EM if ( $diff == 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $diff == 1 1 2 3
51 # Easter Sunday -2 -> Easter Friday.
52 2 ▶ return $EF if ( $diff == -2 );
Branch: 1 branch
BranchTrueFalseTotal
if $diff == -2 1 1 2
53  
54 1 return 0;
55 }
56  
57 6 ▶sub sk_holidays {
Subroutine sk_holidays: called CC=10 SCAR=23.0
Pod documented
58  
59 6 my ($year, $month, $day) = @_;
60  
61 6 my $easter = Date::Simple->new($year, easter($year));
62 # Easter Monday is the day after Easter
63 6 my $em = $easter + 1;
64 # Easter Friday is 2 days before Easter
65 6 my $ef = $easter - 2;
66  
67 # Easter Key ($ek) is a string in the form 'MMDD'
68 6 my $emk = sprintf "%02d%02d", $em->month, $em->day;
69 6 my $efk = sprintf "%02d%02d", $ef->month, $ef->day;
70  
71 # $h is a reference to a hash containing the results
72 6 my $h;
73  
74 6 ▶ if ( ! $month ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $month) { } 1 5 6
elsif (not $day) { } 3 2 5
75  
76 #print "DEBUG: only year given\n";
77 1 $h = {%$FIX};
78 1 $h->{$emk} = $EM;
79 1 $h->{$efk} = $EF;
80  
81 } elsif ( ! $day ) {
82  
83 #print "DEBUG: only year and month given\n";
84 3 my $m = sprintf "%02d", $month;
85 3 foreach my $k (keys %$FIX) {
86 39 ▶ $h->{$k} = $FIX->{$k} if $k =~ m/\A$m/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /\A$m/ 4 35 39
87 }
88 3 ▶ $h->{$emk} = $EM if $emk =~ m/\A$m/;
Branch: 1 branch
BranchTrueFalseTotal
if $emk =~ /\A$m/ 1 2 3
89 3 ▶ $h->{$efk} = $EF if $efk =~ m/\A$m/;
Branch: 1 branch
BranchTrueFalseTotal
if $efk =~ /\A$m/ 1 2 3
90  
91 } else {
92  
93 #print "DEBUG: year, month, and day given\n";
94 2 my $k = sprintf "%02d%02d", $month, $day;
95 2 ▶ $h->{$k} = $FIX->{$k} if exists $FIX->{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $FIX->{$k} 0 2 2
96 2 ▶ $h->{$emk} = $EM if $emk == $k;
Branch: 1 branch
BranchTrueFalseTotal
if $emk == $k 0 2 2
97 2 ▶ $h->{$efk} = $EF if $efk == $k;
Branch: 1 branch
BranchTrueFalseTotal
if $efk == $k 1 1 2
98  
99 }
100  
101 6 return $h;
102 }
103  
104 0 ▶sub is_sk_holiday_today {
Subroutine is_sk_holiday_today: not called CC=1 SCAR=6.9
Pod documented
105 0 my ($year, $month, $day) = (localtime)[ 5, 4, 3 ];
106 0 $year += 1900;
107 0 $month += 1;
108 0 return is_sk_holiday( $year, $month, $day );
109 }
110  
111 1 1;
112  
113 __END__
↑ Summary