Bug 9078 - is_holiday should honour holiday exceptions

Make is_holiday return 0 for holiday exceptions.

Note: This patch makes several current ok tests fail. My first guess is test data is not
constructed ok. More on this later.

Sponsored-by: Universidad Nacional de Córdoba
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passed-QA-by: Paul Poulain <paul.poulain@biblibre.com>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
This commit is contained in:
Tomas Cohen Arazi 2012-11-21 10:43:11 -03:00 committed by Chris Cormack
parent 1d69301468
commit bd60418f9d
1 changed files with 15 additions and 6 deletions

View File

@ -177,22 +177,31 @@ sub addDays {
sub is_holiday {
my ( $self, $dt ) = @_;
my $localdt = $dt->clone();
my $day = $localdt->day;
my $month = $localdt->month;
$localdt->truncate( to => 'day' );
if ( $self->{exception_holidays}->contains($localdt) ) {
# exceptions are not holidays
return 0;
}
my $dow = $localdt->day_of_week;
# Representation fix
# TODO: Shouldn't we shift the rest of the $dow also?
if ( $dow == 7 ) {
$dow = 0;
}
if ( $self->{weekly_closed_days}->[$dow] == 1 ) {
return 1;
}
$localdt->truncate( to => 'day' );
my $day = $localdt->day;
my $month = $localdt->month;
if ( exists $self->{day_month_closed_days}->{$month}->{$day} ) {
return 1;
}
if ( $self->{exception_holidays}->contains($localdt) ) {
return 1;
}
if ( $self->{single_holidays}->contains($localdt) ) {
return 1;
}