File Coverage

blib/lib/Date/Holidays/EnglandWales.pm
Criterion Covered Total %
statement 48 53 90.5
branch 38 48 79.1
condition 45 75 60.0
subroutine 8 9 88.8
pod 0 2 0.0
total 139 187 74.3


line stmt bran cond sub pod time code
1              
2             use 5.008000;
3 1     1   89405 use strict;
  1         4  
4 1     1   5 use warnings;
  1         1  
  1         29  
5 1     1   5  
  1         2  
  1         22  
6             use DateTime;
7 1     1   813 use DateTime::Event::Easter;
  1         459039  
  1         47  
8 1     1   616  
  1         45220  
  1         528  
9             require Exporter;
10             our @ISA = qw(Exporter);
11             our @EXPORT = qw( is_holiday is_uk_holiday );
12             our $VERSION = '0.10';
13              
14              
15             =head1 NAME
16              
17             Date::Holidays::EnglandWales - Determines bank holidays
18              
19             =head1 SYNOPSIS
20              
21             use Date::Holidays::EnglandWales;
22            
23             my ($year, $month, $day) = (localtime)[ 5, 4, 3 ];
24             $year += 1900;
25             $month += 1;
26              
27             my $isodate = "$year-$month-$day";
28              
29             print "It's a bank holiday" if is_holiday($year, $month, $day);
30             print "Sleep in late!" if Date::Holidays::EnglandWales->is_holiday($isodate);
31              
32             =head1 DESCRIPTION
33              
34             Date::Holidays::EnglandWales returns true is a given date is a bank
35             holiday in England and wales.
36              
37             The date can be passed as year, month, day or as an ISO formatted date.
38              
39             This module uses a simple set of rules to determine whether a date is a
40             holiday rather than a static list. This means it isn't limited to just
41             the next few years and wont require maintainance unless the rules are
42             changed.
43              
44             It knows about the proposed bank holiday for the Queen's Diamond Jubilee.
45              
46             =head2 EXPORT
47              
48             is_holiday
49             is_uk_holiday
50              
51             =head1 DEPENDANCIES
52              
53             This module uses the following modules which you can get from CPAN.
54              
55             Time::Piece
56             DateTime::Event::Easter
57              
58             =head1 SEE ALSO
59              
60             Bank Holidays in England and Wales are determined by the Banking and
61             Financial Dealings Act 1971 and by Royal Proclamation. This means that it
62             is possible that they may change from year to year although in practice
63             this does not happen.
64              
65             If you need to be absolutely sure about a date check with the DTI whose
66             website is http://www.dti.gov.uk/
67              
68             =head1 AUTHOR
69              
70             Jason Clifford, E<lt>jason@ukfsn.orgE<gt>
71              
72             =head1 COPYRIGHT AND LICENSE
73              
74             Copyright (C) 2010 by Jason Clifford
75              
76             This library is free software; you can redistribute it and/or modify
77             it under the same terms as Perl itself. That means either the Artistic
78             License or the GNU GPL version 2 or later.
79              
80             =cut
81              
82              
83 0     0 0 0 my ($year, $month, $day) = @_;
84             ($year, $month, $day) = split m{[-/]}, $year unless $month;
85            
86 19     19 0 144 my $dt = DateTime->new(year => $year, month => $month, day => $day)
87 19 100       77 or die "Failed to create DateTime object for $year-$month-$day"
88             . " - invalid date?";
89 19 50       75  
90             if ( $month == 1 ) {
91             return "New Years Day" if (
92             ( $day == 1 && $dt->day_of_week <= 5 ) ||
93 19 100       4876 ( $day == 2 && $dt->day_of_week == 1 ) ||
94 3 100 66     19 ( $day == 3 && $dt->day_of_week == 1 ) );
      66        
      33        
      66        
      33        
95             return undef;
96             }
97              
98 2         26 if ( $year == 2011 && $month == 4 ) {
99             return "Wedding of Prince William and Kate Middleton" if $day == 29;
100             }
101 16 100 100     46  
102 3 100       12 if ( $month == 5 ) {
103             return "Early May Bank Holiday" if (
104             ( $day >= 1 && $day <= 7 && $dt->day_of_week == 1 ) );
105 15 100       30  
106 3 100 66     16 return "Spring Bank Holiday" if (
      66        
107             $year != 2012 && $year != 2022 &&
108             ( $day >= 25 && $dt->day_of_week == 1 ) );
109 2 50 66     12 }
      33        
      66        
110              
111             if ( $year == 2012 && $month == 6 ) {
112             return "Spring Bank Holiday" if $day == 4;
113             return "Queen's Diamond Jubilee" if $day == 5; # Subject to Her Maj not dying first but I cannot be bothered to code for that.
114 13 50 33     28 return undef;
115 0 0       0 }
116 0 0       0  
117 0         0 if ( $year == 2022 && $month == 6) {
118             return "Spring Bank Holiday" if $day == 2;
119             return "Queen's Platinum Jubilee" if $day == 3; # She's still here
120 13 100 100     35 }
121 2 100       10  
122 1 50       7 if ( $year == 2022 && $month == 9 ) {
123             return "State Funeral of Queen Elizabeth II" if $day == 19; # May she rest in peace.
124             }
125 11 100 100     21  
126 1 50       11 if ( $month == 8 ) {
127             return "Summer Bank Holiday" if (
128             $day >= 25 && $dt->day_of_week == 1 );
129 10 100       19 return undef;
130 1 50 33     17 }
131              
132 0         0 if ( $month == 12 ) {
133             return "Christmas Day Bank Holiday" if (
134             ( $day == 25 && $dt->day_of_week <= 5 ) ||
135 9 100       18 ( $day == 26 && $dt->day_of_week == 1 ) ||
136 5 100 66     27 ( $day == 27 && $dt->day_of_week == 1 ) );
      66        
      33        
      66        
      66        
137              
138             return "Boxing Day" if (
139             ( $day == 26 && $dt->day_of_week <= 5 ) ||
140             ( $day == 27 && $dt->day_of_week <= 2 ) ||
141 4 100 66     53 ( $day == 28 && $dt->day_of_week <= 2 ) );
      33        
      33        
      66        
      66        
142              
143             return undef;
144             }
145              
146 3         25 return "Good Friday" if &_GoodFriday($year, $month, $day);
147              
148             # We need to check if the day before the day in question is Easter Sunday
149 4 100       10 my $e = $dt->clone->subtract(days => 1);
150             return "Easter Monday" if &_Easter($e->year, $e->month, $e->day);
151              
152 3         6090 }
153 3 100       2781  
154             my ($year, $month, $day) = @_;
155              
156             my $dt = DateTime->new( year => $year, month => $month, day => $day );
157             my $easter_sunday = DateTime::Event::Easter->new();
158 3     3   37  
159             return $easter_sunday->is($dt);
160 3         11 }
161 3         697  
162             my ($year, $month, $day) = @_;
163 3         375  
164             my $dt = DateTime->new( year => $year, month => $month, day => $day );
165             my $good_friday = DateTime::Event::Easter->new(day=>'Good Friday');
166              
167 4     4   9 return $good_friday->is($dt);
168             }
169 4         9  
170 4         953 1;