File Coverage

lib/Date/Holidays/IE.pm
Criterion Covered Total %
statement 30 35 85.7
branch 18 26 69.2
condition 2 6 33.3
subroutine 5 5 100.0
pod 2 2 100.0
total 57 74 77.0


line stmt bran cond sub pod time code
1             package Date::Holidays::IE;
2 1     1   130719 use strict;
  1         2  
  1         51  
3              
4             =head1 NAME
5              
6             Date::Holidays::IE - Determine Irish holidays - Current EIRE public and bank holiday dates up to 2025
7              
8             =head1 VERSION
9              
10             0.01
11              
12             =head1 SYNOPSIS
13              
14             use Date::Holidays::IE qw( holidays is_holiday);
15              
16             # All EIRE holidays for 2023
17             my $holidays = holidays( year => 2023 );
18              
19             if (is_holiday(
20             year => 2023, month => 12, day => 25
21             )
22             ) {
23             print "No work today!";
24             }
25              
26             # simpler "date" parameter
27             if ( is_holiday( date => '2023-12-25' ) ) {
28             print "No work today!";
29             }
30              
31             =head1 DESCRIPTION
32              
33             A L compatible library with EIRE national holiday dates
34             available from L
35              
36             =head1 EXPORTS
37              
38             Exports C and C functions
39              
40             =cut
41              
42 1     1   6 use base qw( Date::Holidays::Super Exporter );
  1         2  
  1         843  
43              
44             our %EXPORT_TAGS = ( 'all' => [ qw( holidays is_holiday ) ] );
45             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
46             our @EXPORT = qw(holidays is_holiday);
47              
48             our $VERSION = '0.01';
49             our $ALL_HOLIDAYS = _build_all_holidays();
50              
51             =head1 FUNCTIONS
52              
53             =head2 is_holiday
54              
55             =cut
56              
57             sub is_holiday {
58 4 50   4 1 4959 my %args = $_[0] =~ m/[^0-9-]/ ? @_ : ( year => $_[0], month => $_[1], day => $_[2] );
59              
60             my ( $yyyy, $month, $day ) = ( $args{date} )
61             ? $args{date} =~ m{^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})$}
62 4 100       38 : @args{qw( year month day )};
63              
64 4 50 33     60 unless ($yyyy && $month && $day) {
      33        
65 0         0 die "Must specify either 'date' or 'year', 'month' and 'day'";
66             }
67 4 50       22 my $mm = $month ? sprintf('%02d', $month) : undef;
68 4 50       12 my $dd = $day ? sprintf('%02d', $day) : undef;
69              
70 4         14 my $holiday = $ALL_HOLIDAYS->{$yyyy}{$mm}{$dd}{name};
71 4         16 return $holiday;
72             }
73              
74             =head2 holidays
75              
76             =cut
77              
78             sub holidays {
79 2 50   2 1 254878 my %args = $_[0] =~ m/[^0-9-]/ ? @_ : ( year => $_[0], month => $_[1], day => $_[2] );
80              
81             my ( $yyyy, $month, $day ) = ( $args{date} )
82             ? $args{date} =~ m{^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})$}
83 2 100       17 : @args{qw( year month day )};
84              
85 2 50       9 unless ($yyyy) {
86 0         0 die "Must specify either 'date' or 'year'";
87             }
88              
89 2 100       9 my $mm = $month ? sprintf('%02d', $month) : undef;
90 2 100       6 my $dd = $day ? sprintf('%02d', $day) : undef;
91 2         5 my $holidays = { };
92 2 100       6 if ($dd) {
    50          
93 1         4 my $holiday = $ALL_HOLIDAYS->{$yyyy}{$mm}{$dd};
94 1 50       6 if ($holiday) {
95 1         7 $holidays = { "$mm$dd" => $ALL_HOLIDAYS->{$yyyy}{$mm}{$dd}{name} };
96             }
97             } elsif ($mm) {
98 0         0 foreach my $dd ( keys %{$ALL_HOLIDAYS->{$yyyy}{$mm}} ) {
  0         0  
99 0         0 $holidays->{"${mm}${dd}"} = $ALL_HOLIDAYS->{$yyyy}{$mm}{$dd}{name};
100             }
101             } else {
102 1         6 foreach my $mm (keys %{$ALL_HOLIDAYS->{$yyyy}}) {
  1         8  
103 9         14 foreach my $dd ( keys %{$ALL_HOLIDAYS->{$yyyy}{$mm}} ) {
  9         24  
104 10         36 $holidays->{"${mm}${dd}"} = $ALL_HOLIDAYS->{$yyyy}{$mm}{$dd}{name};
105             }
106             }
107             }
108 2         10 return $holidays;
109             }
110              
111              
112             ###############
113              
114             sub _build_all_holidays {
115             return {
116 1     1   84 '2023' => {
117             '08' => {
118             '07' => {
119             'date' => '2023-08-07',
120             'name' => 'August Holiday'
121             }
122             },
123             '02' => {
124             '06' => {
125             'name' => 'Saint Brigid\'s Day',
126             'date' => '2023-02-06'
127             }
128             },
129             '05' => {
130             '01' => {
131             'date' => '2023-05-01',
132             'name' => 'May Day'
133             }
134             },
135             '03' => {
136             '17' => {
137             'name' => 'Saint Patrick\'s Day',
138             'date' => '2023-03-17'
139             }
140             },
141             '06' => {
142             '05' => {
143             'name' => 'June Holiday',
144             'date' => '2023-06-05'
145             }
146             },
147             '10' => {
148             '30' => {
149             'date' => '2023-10-30',
150             'name' => 'October Holiday'
151             }
152             },
153             '12' => {
154             '25' => {
155             'date' => '2023-12-25',
156             'name' => 'Christmas Day'
157             },
158             '26' => {
159             'name' => 'St. Stephen\'s Day',
160             'date' => '2023-12-26'
161             }
162             },
163             '01' => {
164             '01' => {
165             'name' => 'New Year\'s Day',
166             'date' => '2023-01-01'
167             }
168             },
169             '04' => {
170             '10' => {
171             'date' => '2023-04-10',
172             'name' => 'Easter Monday'
173             }
174             }
175             },
176             '2024' => {
177             '04' => {
178             '01' => {
179             'name' => 'Easter Monday',
180             'date' => '2024-04-01'
181             }
182             },
183             '01' => {
184             '01' => {
185             'date' => '2024-01-01',
186             'name' => 'New Year\'s Day'
187             }
188             },
189             '06' => {
190             '03' => {
191             'date' => '2024-06-03',
192             'name' => 'June Holiday'
193             }
194             },
195             '10' => {
196             '28' => {
197             'name' => 'October Holiday',
198             'date' => '2024-10-28'
199             }
200             },
201             '12' => {
202             '26' => {
203             'name' => 'St. Stephen\'s Day',
204             'date' => '2024-12-26'
205             },
206             '25' => {
207             'date' => '2024-12-25',
208             'name' => 'Christmas Day'
209             }
210             },
211             '05' => {
212             '06' => {
213             'date' => '2024-05-06',
214             'name' => 'May Day'
215             }
216             },
217             '03' => {
218             '17' => {
219             'name' => 'Saint Patrick\'s Day',
220             'date' => '2024-03-17'
221             }
222             },
223             '02' => {
224             '05' => {
225             'name' => 'Saint Brigid\'s Day',
226             'date' => '2024-02-05'
227             }
228             },
229             '08' => {
230             '05' => {
231             'date' => '2024-08-05',
232             'name' => 'August Holiday'
233             }
234             }
235             },
236             '2025' => {
237             '02' => {
238             '03' => {
239             'name' => 'Saint Brigid\'s Day',
240             'date' => '2025-02-03'
241             }
242             },
243             '08' => {
244             '04' => {
245             'date' => '2025-08-04',
246             'name' => 'August Holiday'
247             }
248             },
249             '05' => {
250             '05' => {
251             'name' => 'May Day',
252             'date' => '2025-05-05'
253             }
254             },
255             '03' => {
256             '17' => {
257             'name' => 'Saint Patrick\'s Day',
258             'date' => '2025-03-17'
259             }
260             },
261             '06' => {
262             '02' => {
263             'date' => '2025-06-02',
264             'name' => 'June Holiday'
265             }
266             },
267             '10' => {
268             '27' => {
269             'name' => 'October Holiday',
270             'date' => '2025-10-27'
271             }
272             },
273             '12' => {
274             '25' => {
275             'date' => '2025-12-25',
276             'name' => 'Christmas Day'
277             },
278             '26' => {
279             'date' => '2025-12-26',
280             'name' => 'St. Stephen\'s Day'
281             }
282             },
283             '04' => {
284             '21' => {
285             'date' => '2025-04-21',
286             'name' => 'Easter Monday'
287             }
288             },
289             '01' => {
290             '01' => {
291             'name' => 'New Year\'s Day',
292             'date' => '2025-01-01'
293             }
294             }
295             }
296             };
297             }
298              
299             =head1 SEE ALSO
300              
301             =over 4
302              
303             =item *
304              
305             L
306              
307             =back
308              
309             =head1 SUPPORT
310              
311             =head2 Bugs / Feature Requests
312              
313             Please report any bugs or feature requests through the issue tracker
314             at L.
315              
316             =head2 Source Code
317              
318             This is open source software. The code repository is available for
319             public review and contribution under the terms of the license.
320              
321             L
322              
323             =head1 AUTHOR
324              
325             Aaron Trevena teejay@cpan.org
326              
327             =head1 COPYRIGHT AND LICENSE
328              
329             Copyright (C) 2023 by Amtivo Group Plc
330              
331             This library is free software; you can redistribute it and/or modify
332             it under the same terms as Perl itself, either Perl version 5.34.0 or,
333             at your option, any later version of Perl 5 you may have available.
334              
335             =cut
336              
337             1;