From 48b7f958302210662cdbd28b20b9fccd62628ded Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 21 Nov 2012 10:43:11 -0300 Subject: [PATCH] Bug 9078 - is_holiday should honour holiday exceptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Koha/Calendar.pm | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index 3986038..ee63e73 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -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; } -- 1.7.9.5