Skip Menu |
 

This queue is for tickets about the Date-Holidays-UK CPAN distribution.

Report information
The Basics
Id: 15937
Status: new
Priority: 0/
Queue: Date-Holidays-UK

People
Owner: Nobody in particular
Requestors: barbie [...] missbarbell.co.uk
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Holidays for 2008 & extra function
Download (untitled) / with headers
text/plain 335b
Hi Rich, While looking at a suggestion for my module, Calendar::List, I was looking at the best way to get a list of holidays for a given year. I've included a patch that might be of interest using a new function called are_uk_holidays(), which returns the list of dates for a given year. Also included are the dates for 2008 too :)
--- Date-Holidays-UK-0.01/lib/Date/Holidays/UK.pm Tue Mar 16 15:38:42 2004 +++ Date-Holidays-UK-0.01_01/lib/Date/Holidays/UK.pm Fri Nov 18 18:35:51 2005 @@ -3,7 +3,7 @@ use warnings; use base qw(Exporter); our $VERSION = '0.01'; -our @EXPORT = qw( is_uk_holiday ); +our @EXPORT = qw( is_uk_holiday are_uk_holidays ); =head1 NAME @@ -36,6 +36,11 @@ Returns the name of the Holiday that falls on the given day, or undef if there is none. +=head2 are_uk_holidays( $year ) + +Returns the list of holidays that fall in the given day. If there are +no holidays listed for the given year, an empty list is return. + =cut # XXX either programatically fill these, or just do the monkey work @@ -45,42 +50,50 @@ $holidays{ 2004, 1, 1 } = $holidays{ 2005, 1, 3 } = $holidays{ 2006, 1, 2 } = -$holidays{ 2007, 1, 1 } = "New Year's Day"; +$holidays{ 2007, 1, 1 } = +$holidays{ 2008, 1, 1 } = "New Year's Day"; $holidays{ 2004, 4, 9 } = $holidays{ 2005, 3, 25 } = $holidays{ 2006, 4, 14 } = -$holidays{ 2007, 4, 6 } = "Good Friday"; +$holidays{ 2007, 4, 6 } = +$holidays{ 2008, 3, 21 } = "Good Friday"; $holidays{ 2004, 4, 12 } = $holidays{ 2005, 3, 28 } = $holidays{ 2006, 4, 17 } = -$holidays{ 2007, 4, 9 } = "Easter Monday"; +$holidays{ 2007, 4, 9 } = +$holidays{ 2008, 3, 24 } = "Easter Monday"; $holidays{ 2004, 5, 3 } = $holidays{ 2005, 5, 2 } = $holidays{ 2006, 5, 1 } = -$holidays{ 2007, 5, 7 } = "Early May Bank Holiday"; +$holidays{ 2007, 5, 7 } = +$holidays{ 2007, 5, 5 } = "Early May Bank Holiday"; $holidays{ 2004, 5, 31 } = $holidays{ 2005, 5, 30 } = $holidays{ 2006, 5, 29 } = -$holidays{ 2007, 5, 28 } = "Spring Bank Holiday"; +$holidays{ 2007, 5, 28 } = +$holidays{ 2007, 5, 26 } = "Spring Bank Holiday"; $holidays{ 2004, 8, 30 } = $holidays{ 2005, 8, 29 } = $holidays{ 2006, 8, 28 } = -$holidays{ 2007, 8, 27 } = "Summer Bank Holiday"; +$holidays{ 2007, 8, 27 } = +$holidays{ 2008, 8, 25 } = "Summer Bank Holiday"; $holidays{ 2004, 12, 25 } = $holidays{ 2005, 12, 25 } = $holidays{ 2006, 12, 25 } = -$holidays{ 2007, 12, 25 } = "Christmas Day"; +$holidays{ 2007, 12, 25 } = +$holidays{ 2008, 12, 25 } = "Christmas Day"; $holidays{ 2004, 12, 26 } = $holidays{ 2005, 12, 26 } = $holidays{ 2006, 12, 26 } = -$holidays{ 2007, 12, 26 } = "Boxing Day"; +$holidays{ 2007, 12, 26 } = +$holidays{ 2008, 12, 26 } = "Boxing Day"; $holidays{ 2004, 12, 27 } = "Substitute Bank Holiday in lieu of 26th"; @@ -91,6 +104,13 @@ my ($year, $month, $day) = @_; return $holidays{ $year, $month, $day }; } + +sub are_uk_holidays { + my $year = shift; + return sort map {sprintf "%04d-%02d-%02d",split(/\W+/)} grep {/^$year/} keys %holidays; + return keys %holidays; +} + 1; __END__ --- Date-Holidays-UK-0.01/t/holidays.t Tue Mar 16 15:38:42 2004 +++ Date-Holidays-UK-0.01_01/t/holidays.t Fri Nov 18 18:40:33 2005 @@ -1,6 +1,6 @@ #!perl use strict; -use Test::More tests => 3; +use Test::More tests => 5; my $package = 'Date::Holidays::UK'; use_ok( $package ); @@ -9,3 +9,16 @@ "14th January isn't a Bank Holiday (yet)" ); is( is_uk_holiday( 2004, 12, 28 ), "Substitute Bank Holiday in lieu of 25th", "oddball christmas on a Saturday" ); + + +my @list = are_uk_holidays( 2004 ); +is_deeply( \@list, [ "2004-01-01", "2004-04-09", "2004-04-12", + "2004-05-03", "2004-05-31", "2004-08-30", + "2004-12-25", "2004-12-26", "2004-12-27", + "2004-12-28" + ], + "10 holidays in 2004" ); + +@list = are_uk_holidays( 2003 ); +is_deeply( \@list, [], + "no holidays listed for 2003" );


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.