| 1 | package Date::Holidays::BR; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Date::Holidays::Super; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Date::Easter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Time::JulianDay; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | my @ISA = qw(Date::Holidays::Super); | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Date::Holidays::BR - Determine Brazilian public holidays | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | use Date::Holidays::BR; | ||||||||||||||||||||||||||||
| 23 | my ($year, $month, $day) = (localtime)[ 5, 4, 3 ]; | ||||||||||||||||||||||||||||
| 24 | $year += 1900; | ||||||||||||||||||||||||||||
| 25 | $month += 1; | ||||||||||||||||||||||||||||
| 26 | print "Woohoo" if is_br_holiday( $year, $month, $day ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | my $h = br_holidays($year); | ||||||||||||||||||||||||||||
| 29 | printf "Jan. 1st is named '%s'\n", $h->{'0101'}; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head2 new | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Creates a new Date::Holidays::BR object. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | my $mh = Date::Holidays::BR->new(); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 43 | 2 | bless \$self => $self; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head2 is_holiday | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Should at least take three arguments: | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | year (four digits) | ||||||||||||||||||||||||||||
| 51 | month (between 1-12) | ||||||||||||||||||||||||||||
| 52 | day (between 1-31) | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | The return value from is_holiday is either a 1 or a 0 (1 if the | ||||||||||||||||||||||||||||
| 55 | specified date is a holiday, 0 otherwise). | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | if ( $mh->is_holiday( $year, $month, $day ) ) { | ||||||||||||||||||||||||||||
| 58 | # it's a holiday | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =cut | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub is_holiday { | ||||||||||||||||||||||||||
|
Subroutine
is_holiday: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 65 | 0 | return $self->is_br_holiday(@_); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head2 is_br_holiday | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | Similar to is_holiday, but instead of returning 1 if the date is a | ||||||||||||||||||||||||||||
| 71 | holiday returns a string comprising the name of the holidays. In the | ||||||||||||||||||||||||||||
| 72 | event of two or more holidays on the same day (hey, it happens), the | ||||||||||||||||||||||||||||
| 73 | string will comprise the name of all those holidays separated by a | ||||||||||||||||||||||||||||
| 74 | semicolon. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | my $todays_holiday = $mh->is_br_holiday( $year, $month, $day ); | ||||||||||||||||||||||||||||
| 77 | if ( $todays_holiday ) { | ||||||||||||||||||||||||||||
| 78 | print "Today is $todays_holiday.\nDon't bother getting up!\n"; | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 365 | ▶ | sub is_br_holiday { | ||||||||||||||||||||||||||
|
Subroutine
is_br_holiday: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 365 | my $self = shift; | |||||||||||||||||||||||||||
| 85 | 365 | my ($year, $month, $day) = @_; | |||||||||||||||||||||||||||
| 86 | 365 | ▶ | defined $year || return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 365 | ▶ | defined $month || return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 365 | ▶ | defined $day || return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 365 | my $holidays = $self->holidays($year); | |||||||||||||||||||||||||||
| 91 | 365 | ▶ | if (defined $holidays->{$month} and defined $holidays->{$month}{$day}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $holidays->{$month} and defined $holidays->{$month}{$day}
MC/DC100%2/2
defined $holidays->{$month} and defined $holidays->{$month}{$day}
defined $holidays->{$month}
defined $holidays->{$month}{$day}
Truth table100%3/3
A and B
A= defined $holidays->{$month}B= defined $holidays->{$month}{$day}
| |||||||||||||||||||||||||||||
| 92 | 9 | return $holidays->{$month}{$day}; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||||||||||
| 95 | 356 | return undef; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head2 holidays | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Should take at least one argument: | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | year (four digits) | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | Returns a reference to a hash, where the keys are date represented as | ||||||||||||||||||||||||||||
| 107 | four digits, the two first representing month (01-12) and the last two | ||||||||||||||||||||||||||||
| 108 | representing day (01-31). | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | The value for the key in question is the local name for the holiday | ||||||||||||||||||||||||||||
| 111 | indicated by the day. In the event of two or more holidays on the same | ||||||||||||||||||||||||||||
| 112 | day (yes, it happens!), the values will comprise the name of all those | ||||||||||||||||||||||||||||
| 113 | holidays separated by a semicolon. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | my $years_holidays = holidays( $year ); | ||||||||||||||||||||||||||||
| 116 | for (keys %$years_holidays) { | ||||||||||||||||||||||||||||
| 117 | my ($day, $month) = /(..)(..)/; | ||||||||||||||||||||||||||||
| 118 | print "$day/$month - $years_holidays->$_\n"; | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =cut | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 367 | ▶ | sub holidays { | ||||||||||||||||||||||||||
|
Subroutine
holidays: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 367 | my $self = shift; | |||||||||||||||||||||||||||
| 125 | 367 | my $year = shift; | |||||||||||||||||||||||||||
| 126 | 367 | ▶ | defined $year || return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 366 | my %holidays = ( | |||||||||||||||||||||||||||
| 129 | 1 => { | ||||||||||||||||||||||||||||
| 130 | 1 => 'Confraternização Universal', | ||||||||||||||||||||||||||||
| 131 | }, | ||||||||||||||||||||||||||||
| 132 | 4 => { | ||||||||||||||||||||||||||||
| 133 | 21 => 'Tiradentes', | ||||||||||||||||||||||||||||
| 134 | }, | ||||||||||||||||||||||||||||
| 135 | 5 => { | ||||||||||||||||||||||||||||
| 136 | 1 => 'Dia do Trabalho', | ||||||||||||||||||||||||||||
| 137 | }, | ||||||||||||||||||||||||||||
| 138 | 9 => { | ||||||||||||||||||||||||||||
| 139 | 7 => 'Independência do Brasil', | ||||||||||||||||||||||||||||
| 140 | }, | ||||||||||||||||||||||||||||
| 141 | 10 => { | ||||||||||||||||||||||||||||
| 142 | 12 => 'Nossa Senhora Aparecida', | ||||||||||||||||||||||||||||
| 143 | }, | ||||||||||||||||||||||||||||
| 144 | 11 => { | ||||||||||||||||||||||||||||
| 145 | 2 => 'Dia de Finados', | ||||||||||||||||||||||||||||
| 146 | 15 => 'Proclamação da República', | ||||||||||||||||||||||||||||
| 147 | }, | ||||||||||||||||||||||||||||
| 148 | 12 => { | ||||||||||||||||||||||||||||
| 149 | 25 => 'Natal', | ||||||||||||||||||||||||||||
| 150 | }, | ||||||||||||||||||||||||||||
| 151 | ); | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 366 | my ($emonth, $eday) = gregorian_easter($year); | |||||||||||||||||||||||||||
| 154 | # $holidays{$emonth}{$eday} = 'Páscoa'; | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 366 | my $jd = julian_day($year, $emonth, $eday); | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 366 | my (undef, $smonth, $sday) = inverse_julian_day($jd - 2); | |||||||||||||||||||||||||||
| 159 | 366 | $holidays{$smonth}{$sday} = 'Sexta-feira da Paixão'; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 366 | return \%holidays; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 3 | 42; | |||||||||||||||||||||||||||
| 165 | __END__ | ||||||||||||||||||||||||||||