@@ -, +, @@ same day --- C4/Calendar.pm | 1 + Koha/Calendar.pm | 5 ++--- t/Calendar.t | 11 ++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) --- a/C4/Calendar.pm +++ a/C4/Calendar.pm @@ -733,3 +733,4 @@ __END__ Koha Physics Library UNLP =cut + --- a/Koha/Calendar.pm +++ a/Koha/Calendar.pm @@ -71,7 +71,7 @@ sub _holidays { # Add holidays for each branch my $holidays_sth = $dbh->prepare( -'SELECT day, month, year, isexception FROM special_holidays WHERE branchcode = ?' +'SELECT day, month, year, MAX(isexception) FROM special_holidays WHERE branchcode = ? GROUP BY day, month, year' ); $holidays_sth->execute($self->{branchcode}); @@ -83,11 +83,10 @@ sub _holidays { . sprintf( "%02d", $month ) . sprintf( "%02d", $day ); - $holidays->{$datestring} = !$exception; + $holidays->{$datestring} = $exception ? 0 : 1; } $cache->set_in_cache( $key, $holidays, { expiry => 76800 } ); } - return $holidays // {}; } --- a/t/Calendar.t +++ a/t/Calendar.t @@ -31,7 +31,7 @@ use Module::Load::Conditional qw/check_install/; BEGIN { if ( check_install( module => 'Test::DBIx::Class' ) ) { - plan tests => 39; + plan tests => 40; } else { plan skip_all => "Need Test::DBIx::Class" } @@ -73,6 +73,8 @@ fixtures_ok [ [ 'MPL', 1, 6, 2011, '', '', 0 ], [ 'MPL', 4, 7, 2012, '', '', 0 ], [ 'CPL', 6, 8, 2012, '', '', 0 ], + [ 'MPL', 7, 7, 2012, '', '', 1 ], # holiday exception + [ 'MPL', 7, 7, 2012, '', '', 0 ], # holiday ], ], "add fixtures"; @@ -139,6 +141,12 @@ my $holiday_for_another_branch = DateTime->new( day => 6, # This is a monday ); +my $holiday_excepted = DateTime->new( + year => 2012, + month => 7, + day => 7, # Both a holiday and exception +); + { # Syspref-agnostic tests is ( $saturday->day_of_week, 6, '\'$saturday\' is actually a saturday (6th day of week)'); is ( $sunday->day_of_week, 7, '\'$sunday\' is actually a sunday (7th day of week)'); @@ -151,6 +159,7 @@ my $holiday_for_another_branch = DateTime->new( is ( $cal->is_holiday($notspecial), 0, 'Fixed single date that is not a holiday test' ); is ( $cal->is_holiday($sunday_exception), 0, 'Exception holiday is not a closed day test' ); is ( $cal->is_holiday($holiday_for_another_branch), 0, 'Holiday defined for another branch should not be defined as an holiday' ); + is ( $cal->is_holiday($holiday_excepted), 0, 'Holiday defined and excepted should not be a holiday' ); } { # Bugzilla #8966 - is_holiday truncates referenced date --