Bug 9078 - is_holiday should honour holiday exceptions
authorTomas Cohen Arazi <tomascohen@gmail.com>
Wed, 21 Nov 2012 13:43:11 +0000 (10:43 -0300)
committerJared Camins-Esakov <jcamins@cpbibliography.com>
Thu, 22 Nov 2012 14:27:21 +0000 (09:27 -0500)
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>
Koha/Calendar.pm

index 3986038..ee63e73 100644 (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;
     }