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   86793 use strict;
  1         4  
4 1     1   4 use warnings;
  1         2  
  1         16  
5 1     1   8  
  1         1  
  1         19  
6             use DateTime;
7 1     1   817 use DateTime::Event::Easter;
  1         460431  
  1         37  
8 1     1   512  
  1         44651  
  1         507  
9             require Exporter;
10             our @ISA = qw(Exporter);
11             our @EXPORT = qw( is_holiday is_uk_holiday );
12             our $VERSION = '0.09';
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 135 my $dt = DateTime->new(year => $year, month => $month, day => $day)
87 19 100       82 or die "Failed to create DateTime object for $year-$month-$day"
88             . " - invalid date?";
89 19 50       65  
90             if ( $month == 1 ) {
91             return "New Years Day" if (
92             ( $day == 1 && $dt->day_of_week <= 5 ) ||
93 19 100       4976 ( $day == 2 && $dt->day_of_week == 1 ) ||
94 3 100 66     18 ( $day == 3 && $dt->day_of_week == 1 ) );
      66        
      33        
      66        
      33        
95             return undef;
96             }
97              
98 2         24 if ( $year == 2011 && $month == 4 ) {
99             return "Wedding of Prince William and Kate Middleton" if $day == 29;
100             }
101 16 100 100     50  
102 3 100       21 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     14 return "Spring Bank Holiday" if (
      66        
107             $year != 2012 && $year != 2022 &&
108             ( $day >= 25 && $dt->day_of_week == 1 ) );
109 2 50 66     30 }
      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     26 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       21  
122 1 50       18 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     26  
126 1 50       8 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     5 }
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       15 ( $day == 26 && $dt->day_of_week == 1 ) ||
136 5 100 66     28 ( $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     44 ( $day == 28 && $dt->day_of_week <= 2 ) );
      33        
      33        
      66        
      66        
142              
143             return undef;
144             }
145              
146 3         27 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         6205 }
153 3 100       2740  
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   47  
159             return $easter_sunday->is($dt);
160 3         8 }
161 3         745  
162             my ($year, $month, $day) = @_;
163 3         371  
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   8 return $good_friday->is($dt);
168             }
169 4         10  
170 4         952 1;