| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Date::Holidays::BR; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
137223
|
use warnings; |
|
|
3
|
|
|
|
|
250
|
|
|
|
3
|
|
|
|
|
111
|
|
|
4
|
3
|
|
|
3
|
|
110
|
use strict; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
213
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
9126
|
use Date::Holidays::Super; |
|
|
3
|
|
|
|
|
668
|
|
|
|
3
|
|
|
|
|
81
|
|
|
7
|
3
|
|
|
3
|
|
2701
|
use Date::Easter; |
|
|
3
|
|
|
|
|
17747
|
|
|
|
3
|
|
|
|
|
209
|
|
|
8
|
3
|
|
|
3
|
|
2865
|
use Time::JulianDay; |
|
|
3
|
|
|
|
|
16478
|
|
|
|
3
|
|
|
|
|
1687
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my @ISA = qw(Date::Holidays::Super); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Date::Holidays::BR - Determine Brazilian public holidays |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub new { |
|
42
|
2
|
|
|
2
|
1
|
24
|
my $self = shift; |
|
43
|
2
|
|
|
|
|
10
|
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
|
|
|
|
|
|
|
sub is_holiday { |
|
64
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
65
|
0
|
|
|
|
|
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
|
|
|
|
|
|
|
sub is_br_holiday { |
|
84
|
365
|
|
|
365
|
1
|
768
|
my $self = shift; |
|
85
|
365
|
|
|
|
|
751
|
my ($year, $month, $day) = @_; |
|
86
|
365
|
50
|
|
|
|
792
|
defined $year || return undef; |
|
87
|
365
|
50
|
|
|
|
619
|
defined $month || return undef; |
|
88
|
365
|
50
|
|
|
|
655
|
defined $day || return undef; |
|
89
|
|
|
|
|
|
|
|
|
90
|
365
|
|
|
|
|
756
|
my $holidays = $self->holidays($year); |
|
91
|
365
|
100
|
100
|
|
|
1804
|
if (defined $holidays->{$month} and defined $holidays->{$month}{$day}) { |
|
92
|
9
|
|
|
|
|
85
|
return $holidays->{$month}{$day}; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
else { |
|
95
|
356
|
|
|
|
|
2819
|
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
|
|
|
|
|
|
|
sub holidays { |
|
124
|
367
|
|
|
367
|
1
|
449
|
my $self = shift; |
|
125
|
367
|
|
|
|
|
403
|
my $year = shift; |
|
126
|
367
|
100
|
|
|
|
621
|
defined $year || return undef; |
|
127
|
|
|
|
|
|
|
|
|
128
|
366
|
|
|
|
|
3936
|
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
|
|
|
|
|
1095
|
my ($emonth, $eday) = gregorian_easter($year); |
|
154
|
|
|
|
|
|
|
# $holidays{$emonth}{$eday} = 'Páscoa'; |
|
155
|
|
|
|
|
|
|
|
|
156
|
366
|
|
|
|
|
5616
|
my $jd = julian_day($year, $emonth, $eday); |
|
157
|
|
|
|
|
|
|
|
|
158
|
366
|
|
|
|
|
2965
|
my (undef, $smonth, $sday) = inverse_julian_day($jd - 2); |
|
159
|
366
|
|
|
|
|
5124
|
$holidays{$smonth}{$sday} = 'Sexta-feira da Paixão'; |
|
160
|
|
|
|
|
|
|
|
|
161
|
366
|
|
|
|
|
958
|
return \%holidays; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
42; |
|
165
|
|
|
|
|
|
|
__END__ |