@@ -, +, @@ - checkout an item with a return date < today - checkin the item and verify the suspension period is well calculated (depending on the holidays). - prove t/db_dependent/Holidays.t - t/Calendar.t --- Koha/Calendar.pm | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) --- a/Koha/Calendar.pm +++ a/Koha/Calendar.pm @@ -52,6 +52,21 @@ sub _init { 1; } + $self->{days_mode} = C4::Context->preference('useDaysMode'); + $self->{test} = 0; + return; +} + + +our ( $exception_holidays, $single_holidays ); +sub exception_holidays { + my ( $self ) = @_; + my $dbh = C4::Context->dbh; + my $branch = $self->{branchcode}; + if ( $exception_holidays ) { + $self->{exception_holidays} = $exception_holidays; + return $exception_holidays; + } my $exception_holidays_sth = $dbh->prepare( 'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 1' ); @@ -68,12 +83,23 @@ sub _init { } $self->{exception_holidays} = DateTime::Set->from_datetimes( dates => $dates ); + $exception_holidays = $self->{exception_holidays}; + return $exception_holidays; +} +sub single_holidays { + my ( $self ) = @_; + my $dbh = C4::Context->dbh; + my $branch = $self->{branchcode}; + if ( $single_holidays ) { + $self->{single_holidays} = $single_holidays; + return $single_holidays; + } my $single_holidays_sth = $dbh->prepare( 'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0' ); $single_holidays_sth->execute( $branch ); - $dates = []; + my $dates = []; while ( my ( $day, $month, $year ) = $single_holidays_sth->fetchrow ) { push @{$dates}, DateTime->new( @@ -84,11 +110,9 @@ sub _init { )->truncate( to => 'day' ); } $self->{single_holidays} = DateTime::Set->from_datetimes( dates => $dates ); - $self->{days_mode} = C4::Context->preference('useDaysMode'); - $self->{test} = 0; - return; + $single_holidays = $self->{single_holidays}; + return $single_holidays; } - sub addDate { my ( $self, $startdate, $add_duration, $unit ) = @_; @@ -188,7 +212,7 @@ sub is_holiday { $localdt->truncate( to => 'day' ); - if ( $self->{exception_holidays}->contains($localdt) ) { + if ( $self->exception_holidays->contains($localdt) ) { # exceptions are not holidays return 0; } @@ -208,7 +232,7 @@ sub is_holiday { return 1; } - if ( $self->{single_holidays}->contains($localdt) ) { + if ( $self->single_holidays->contains($localdt) ) { return 1; } @@ -342,7 +366,7 @@ sub clear_weekly_closed_days { sub add_holiday { my $self = shift; my $new_dt = shift; - my @dt = $self->{single_holidays}->as_list; + my @dt = $self->single_holidays->as_list; push @dt, $new_dt; $self->{single_holidays} = DateTime::Set->from_datetimes( dates => \@dt ); --