| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 51 | # Easter Sunday -2 -> Easter Friday. | ||||||||||||||
| 52 | 2 | ▶ | return $EF if ( $diff == -2 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 87 | } | ||||||||||||||
| 88 | 3 | ▶ | $h->{$emk} = $EM if $emk =~ m/\A$m/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 89 | 3 | ▶ | $h->{$efk} = $EF if $efk =~ m/\A$m/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 96 | 2 | ▶ | $h->{$emk} = $EM if $emk == $k; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 97 | 2 | ▶ | $h->{$efk} = $EF if $efk == $k; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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__ | ||||||||||||||