File Coverage

blib/lib/Date/Holidays/AT.pm
Criterion Covered Total %
statement 18 102 17.6
branch 0 12 0.0
condition 0 3 0.0
subroutine 6 8 75.0
pod 0 1 0.0
total 24 126 19.0


line stmt bran cond sub pod time code
1             package Date::Holidays::AT;
2              
3 1     1   21572 use warnings;
  1         2  
  1         31  
4 1     1   4 use strict;
  1         2  
  1         23  
5              
6             # Stock modules
7 1     1   1312 use Time::Local;
  1         1656  
  1         61  
8 1     1   751 use POSIX qw(strftime);
  1         7282  
  1         5  
9              
10             # Prerequisite
11 1     1   2188 use Date::Calc 5.0 qw(Add_Delta_Days Easter_Sunday Day_of_Week This_Year);
  1         10148  
  1         136  
12              
13             require Exporter;
14              
15             our @ISA = qw(Exporter);
16             our @EXPORT_OK = qw(holidays);
17 1     1   728 use version; our $VERSION = qv("0.1.4");
  1         2120  
  1         6  
18              
19             sub holidays {
20 0     0 0   my %parameters = (
21             YEAR => This_Year(),
22             WHERE => ['common'],
23             FORMAT => "%s",
24             WEEKENDS => 1,
25             @_,
26             );
27              
28             # Easter is the key to everything
29 0           my ($year, $month, $day) = Easter_Sunday($parameters{'YEAR'});
30              
31             # Aliases for holidays
32             #
33             # neuj = New year's day
34             # hl3k = Heilige 3 Koenige
35             # jose = Josef
36             # tdar = Staatsfeiertag (Tag der Arbeit)
37             # flor = Florian
38             # mahi = Mariae Himmelfahrt
39             # rupe = Rupert
40             # volk = Tag der Volksabstimmung
41             # nati = Nationalfeiertag
42             # alhe = Allerheiligen
43             # mart = Martin
44             # leop = Leopold
45             # maem = Mariae Empfaengnis
46             # heab = Heiliger Abend
47             # chri = Christtag
48             # stef = Stefanitag
49             # silv = Silvester
50             # karf = Karfreitag
51             # ostm = Ostermontag
52             # himm = Christi Himmelfahrt
53             # pfim = Pfingstmontag
54             # fron = Fronleichnam
55              
56             # Fixed-date holidays
57             #
58 0           my (%holiday, %holidays);
59              
60 0           $holiday{'neuj'} = _date2timestamp($year, 1, 1); # New year's day
61 0           $holiday{'hl3k'} = _date2timestamp($year, 1, 6); # Heilige 3 Koenige
62 0           $holiday{'jose'} = _date2timestamp($year, 3, 19); # Josef
63 0           $holiday{'tdar'} = _date2timestamp($year, 5, 1); # Staatsfeiertag (Tag der Arbeit)
64 0           $holiday{'flor'} = _date2timestamp($year, 5, 4); # Florian
65 0           $holiday{'mahi'} = _date2timestamp($year, 8, 15); # Mariae Himmelfahrt
66 0           $holiday{'rupe'} = _date2timestamp($year, 9, 24); # Rupert
67 0           $holiday{'volk'} = _date2timestamp($year, 10, 10); # Tag der Volksabstimmung
68 0           $holiday{'nati'} = _date2timestamp($year, 10, 26); # Nationalfeiertag
69 0           $holiday{'alhe'} = _date2timestamp($year, 11, 1); # Allerheiligen
70 0           $holiday{'mart'} = _date2timestamp($year, 11, 11); # Martin
71 0           $holiday{'leop'} = _date2timestamp($year, 11, 15); # Leopold
72 0           $holiday{'maem'} = _date2timestamp($year, 12, 8); # Mariae Empfaengnis
73 0           $holiday{'heab'} = _date2timestamp($year, 12, 24); # Heiliger Abend
74 0           $holiday{'chri'} = _date2timestamp($year, 12, 25); # Christtag
75 0           $holiday{'stef'} = _date2timestamp($year, 12, 26); # Stefanitag
76 0           $holiday{'silv'} = _date2timestamp($year, 12, 31); # Silvester
77              
78             # Holidays relative to Easter
79             #
80             # Karfreitag (Good Friday) = Easter Sunday minus 2 days
81 0           my ($j_karf, $m_karf, $t_karf) = Date::Calc::Add_Delta_Days($year, $month, $day, -2);
82 0           $holiday{'karf'} = _date2timestamp($j_karf, $m_karf, $t_karf);
83              
84             # Ostermontag (Easter Monday) = Easter Sunday plus 1 day
85 0           my ($j_ostm, $m_ostm, $t_ostm) = Date::Calc::Add_Delta_Days($year, $month, $day, 1);
86 0           $holiday{'ostm'} = _date2timestamp($j_ostm, $m_ostm, $t_ostm);
87              
88             # Christi Himmelfahrt (Ascension Day) = Easter Sunday plus 39 days
89 0           my ($j_himm, $m_himm, $t_himm) = Date::Calc::Add_Delta_Days($year, $month, $day, 39);
90 0           $holiday{'himm'} = _date2timestamp($j_himm, $m_himm, $t_himm);
91              
92             # Pfingsmontag (Whit Monday) = Easter Sunday plus 50 days
93 0           my ($j_pfim, $m_pfim, $t_pfim) = Date::Calc::Add_Delta_Days($year, $month, $day, 50);
94 0           $holiday{'pfim'} = _date2timestamp($j_pfim, $m_pfim, $t_pfim);
95              
96             # Fronleichnam (Corpus Christi) = Easter Sunday plus 60 days
97 0           my ($j_fron, $m_fron, $t_fron) = Date::Calc::Add_Delta_Days($year, $month, $day, 60);
98 0           $holiday{'fron'} = _date2timestamp($j_fron, $m_fron, $t_fron);
99              
100             # Common holidays througout Austria
101 0           @{ $holidays{'common'} } = qw(neuj hl3k ostm tdar himm pfim fron mahi nati alhe maem chri stef);
  0            
102              
103              
104             # Extra for Burgenland
105 0           @{ $holidays{'B'} } = qw(jose karf mart heab silv );
  0            
106             # Extra for Kaernten
107 0           @{ $holidays{'K'} } = qw( karf volk heab silv );
  0            
108             # Extra for Niederoesterreich
109 0           @{ $holidays{'NOE'} } = qw( karf leop heab silv );
  0            
110             # Extra for Oberoesterreich
111 0           @{ $holidays{'OOE'} } = qw( karf flor heab silv );
  0            
112             # Extra for Salzburg
113 0           @{ $holidays{'S'} } = qw( karf rupe heab silv );
  0            
114             # Extra for Steiermark
115 0           @{ $holidays{'ST'} } = qw(jose karf heab silv );
  0            
116             # Extra for Tirol
117 0           @{ $holidays{'T'} } = qw(jose karf heab silv );
  0            
118             # Extra for Voralberg
119 0           @{ $holidays{'V'} } = qw(jose karf heab silv );
  0            
120             # Extra for Wien
121 0           @{ $holidays{'W'} } = qw( karf leop heab silv );
  0            
122              
123             # Build list for returning
124             #
125 0           my %holidaylist;
126             # See what holidays shall be printed
127 0           my $wantall = 0;
128 0           foreach (@{$parameters{'WHERE'}}){
  0            
129 0 0         if ($_ eq 'all'){
130 0           $wantall = 1;
131             }
132             }
133 0 0         if (1 == $wantall){
134             # All holidays if 'all' is in the WHERE parameter list.
135 0           %holidaylist = %holiday;
136             }else{
137             # Only specified regions
138 0           foreach my $scope (@{$parameters{'WHERE'}}){
  0            
139 0           foreach my $alias(@{$holidays{$scope}}){
  0            
140 0           $holidaylist{$alias} = $holiday{$alias};
141             }
142             }
143             }
144              
145              
146             # Add the most obscure holidays that were requested through
147             # the ADD parameter
148 0 0         if ($parameters{'ADD'}) {
149 0           foreach my $add (@{ $parameters{'ADD'} }) {
  0            
150 0           $holidaylist{$add} = $holiday{$add};
151             }
152             }
153              
154             # If WEEKENDS => 0 was passed, weed out holidays on weekends
155             #
156 0 0         unless (1 == $parameters{'WEEKENDS'}) {
157              
158             # Walk the list of holidays
159 0           foreach my $alias (keys(%holidaylist)) {
160              
161             # Get day of week. Since we're no longer
162             # in Date::Calc's world, use localtime()
163 0           my $dow = (localtime($holiday{$alias}))[6];
164              
165             # dow 6 = Saturday, dow 0 = Sunday
166 0 0 0       if ((6 == $dow) or (0 == $dow)) {
167              
168             # Kick this day from the list
169 0           delete $holidaylist{$alias};
170             }
171             }
172             }
173              
174             # Sort values stored in the hash for returning
175             #
176 0           my @returnlist;
177 0           foreach (sort { $holidaylist{$a} <=> $holidaylist{$b} } (keys(%holidaylist))) {
  0            
178              
179             # See if this platform has strftime(%s)
180             # if not, inject seconds manually into format string.
181 0           my $formatstring = $parameters{'FORMAT'};
182 0 0         if (strftime('%s', localtime($holidaylist{$_})) eq '%s') {
183 0           $formatstring =~ s/%{0}%s/$holidaylist{$_}/g;
184             }
185              
186             # Inject the holiday's alias name into the format string
187             # if it was requested by adding %#.
188 0           $formatstring =~ s/%{0}%#/$_/;
189 0           push @returnlist, strftime($formatstring, localtime($holidaylist{$_}));
190             }
191 0           return \@returnlist;
192             }
193              
194             sub _date2timestamp {
195              
196             # Turn Date::Calc's y/m/d format into a UNIX timestamp
197 0     0     my ($y, $m, $d) = @_;
198 0           my $timestamp = timelocal(0, 0, 0, $d, ($m - 1), $y);
199 0           return $timestamp;
200             }
201              
202             1;
203             __END__