use DateTime::Set;
use DateTime::Duration;
use C4::Context;
-use Koha::Cache;
+use Koha::Caches;
use Carp;
sub new {
return;
}
-
-# FIXME: use of package-level variables for caching the holiday
-# lists breaks persistance engines. As of 2013-12-10, the RM
-# is allowing this with the expectation that prior to release of
-# 3.16, bug 8089 will be fixed and we can switch the caching over
-# to Koha::Cache.
-
-our ( $exception_holidays, $single_holidays ); ## no need for $single_holidays now, surely?
-
sub exception_holidays {
my ( $self ) = @_;
+
+ my $cache = Koha::Caches->get_instance();
+ my $cached = $cache->get_from_cache('exception_holidays');
+ return $cached if $cached;
+
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'
);
day => $day,
month => $month,
year => $year,
- time_zone => C4::Context->tz()
+ time_zone => "floating",
)->truncate( to => 'day' );
}
$self->{exception_holidays} =
DateTime::Set->from_datetimes( dates => $dates );
- $exception_holidays = $self->{exception_holidays};
- return $exception_holidays;
+ $cache->set_in_cache( 'exception_holidays', $self->{exception_holidays} );
+ return $self->{exception_holidays};
}
sub single_holidays {
my ( $self, $date ) = @_;
my $branchcode = $self->{branchcode};
- my $cache = Koha::Cache->get_instance();
+ my $cache = Koha::Caches->get_instance();
my $single_holidays = $cache->get_from_cache('single_holidays');
-=for
-$single_holidays looks like this..
-
-\ {
- CPL [
- [0] 20131122,
- [1] 20131123,
- [2] 20131124
- ],
- MPL [
- [0] 20131122,
- [1] 20131123,
- [2] 20131124
- ]
-}
-
-=cut
+ # $single_holidays looks like:
+ # {
+ # CPL => [
+ # [0] 20131122,
+ # ...
+ # ],
+ # ...
+ # }
unless ($single_holidays) {
my $dbh = C4::Context->dbh;
my $single_holidays_sth = $dbh->prepare(
'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0'
);
- $single_holidays_sth->execute($branchcode);
+ $single_holidays_sth->execute($br);
my @ymd_arr;
while ( my ( $day, $month, $year ) =
day => $day,
month => $month,
year => $year,
- time_zone => C4::Context->tz()
+ time_zone => 'floating',
)->truncate( to => 'day' );
push @ymd_arr, $dt->ymd('');
}
$single_holidays->{$br} = \@ymd_arr;
} # br
$cache->set_in_cache( 'single_holidays', $single_holidays,
- 76800 ) #24 hrs ;
+ { expiry => 76800 } ) #24 hrs ;
}
my $holidays = ( $single_holidays->{$branchcode} );
for my $hols (@$holidays ) {
my $day = $localdt->day;
my $month = $localdt->month;
+ #Change timezone to "floating" before doing any calculations or comparisons
+ $localdt->set_time_zone("floating");
$localdt->truncate( to => 'day' );
return;
}
-
-sub add_dummy_holiday {
- my ( $self, $new_dt ) = @_;
-
- my $cache = Koha::Cache->get_instance();
- my $single_holidays = $cache->get_from_cache('single_holidays');
-
- # add a dummy holiday to the holiday cache...
- my $ymd = $new_dt->ymd('');
- $single_holidays->{'MPL'} = [$ymd];
- $cache->set_in_cache( 'single_holidays', $single_holidays, 76800 );
-
- # ...but *dont* reset the cache, as this holiday was not really written to the db
- # its only used to mock a holiday insert for 1 test in t/db_dependent/Holidays.t
-
- # is( $koha_calendar->is_holiday($custom_holiday), 0, '2013-11-10 does not start off as a holiday' );
- # $koha_calendar->add_dummy_holiday($custom_holiday );
- # is( $koha_calendar->is_holiday($custom_holiday), 1, 'able to add holiday for testing' );
-
-}
-
-
1;
__END__
Koha::Calendar - Object containing a branches calendar
-=head1 VERSION
-
-This documentation refers to Koha::Calendar version 0.0.1
-
=head1 SYNOPSIS
use Koha::Calendar