use strict;
use warnings;
-use vars qw($VERSION @EXPORT);
+use vars qw(@EXPORT);
use Carp;
use Date::Calc qw( Date_to_Days Today);
use C4::Context;
-use Koha::Cache;
+use Koha::Caches;
use constant ISO_DATE_FORMAT => "%04d-%02d-%02d";
# changed the 'single_holidays' table, lets force/reset its cache
- my $cache = Koha::Cache->get_instance();
+ my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
+ $cache->clear_from_cache( 'exception_holidays') ;
return $self;
$self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
# changed the 'single_holidays' table, lets force/reset its cache
- my $cache = Koha::Cache->get_instance();
+ my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
+ $cache->clear_from_cache( 'exception_holidays') ;
return $self;
}
$self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
# changed the 'single_holidays' table, lets force/reset its cache
- my $cache = Koha::Cache->get_instance();
+ my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
+ $cache->clear_from_cache( 'exception_holidays') ;
return $self;
}
$self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
# changed the 'single_holidays' table, lets force/reset its cache
- my $cache = Koha::Cache->get_instance();
+ my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
+ $cache->clear_from_cache( 'exception_holidays') ;
return $self;
}
}
# changed the 'single_holidays' table, lets force/reset its cache
- my $cache = Koha::Cache->get_instance();
+ my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
+ $cache->clear_from_cache( 'exception_holidays') ;
return $self;
}
$sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
# changed the 'single_holidays' table, lets force/reset its cache
- my $cache = Koha::Cache->get_instance();
+ my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
+ $cache->clear_from_cache( 'exception_holidays') ;
}
$sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
# changed the 'single_holidays' table, lets force/reset its cache
- my $cache = Koha::Cache->get_instance();
+ my $cache = Koha::Caches->get_instance();
$cache->clear_from_cache( 'single_holidays') ;
+ $cache->clear_from_cache( 'exception_holidays') ;
}
=head2 isHoliday
return 1;
}
-=head2 addDate
-
- my ($day, $month, $year) = $calendar->addDate($date, $offset)
-
-C<$startdate> is the starting date of the interval.
-
-C<$offset> Is the number of days that this function has to count from $date.
-
-=cut
-
-sub addDate {
- my ($self, $startdate, $offset) = @_;
- $startdate = eval { output_pref( { dt => dt_from_string( $startdate ), dateonly => 1, dateformat => 'iso' } ); };
- my ( $year, $month, $day) = split( "-", $startdate );
- my $daystep = 1;
- if ($offset < 0) { # In case $offset is negative
- # $offset = $offset*(-1);
- $daystep = -1;
- }
- my $daysMode = C4::Context->preference('useDaysMode');
- if ($daysMode eq 'Datedue') {
- ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $offset );
- while ($self->isHoliday($day, $month, $year)) {
- ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $daystep);
- }
- } elsif($daysMode eq 'Calendar') {
- while ($offset != 0) {
- ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $daystep);
- if (!($self->isHoliday($day, $month, $year))) {
- $offset = $offset - $daystep;
- }
- }
- } else { ## ($daysMode eq 'Days')
- ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $offset );
- }
- my $date_ret = sprintf(ISO_DATE_FORMAT,$year,$month,$day);
- $date_ret = eval { output_pref( { dt => dt_from_string( $date_ret), dateonly => 1, dateformat => 'iso' } ); };
- return($date_ret);
-}
-
-=head2 daysBetween
-
- my $daysBetween = $calendar->daysBetween($startdate, $enddate)
-
-C<$startdate> and C<$enddate> define the interval.
-
-Returns the number of non-holiday days in the interval.
-useDaysMode syspref has no effect here.
-=cut
-
-sub daysBetween {
- my $self = shift or return;
- my $startdate = shift or return;
- my $enddate = shift or return;
- $startdate = eval { output_pref( { dt => dt_from_string( $startdate ), dateonly => 1, dateformat => 'iso' } ); };
- $enddate = eval { output_pref( { dt => dt_from_string( $enddate ), dateonly => 1, dateformat => 'iso' } ); };
- my ( $yearFrom, $monthFrom, $dayFrom) = split( "-", $startdate);
- my ( $yearTo, $monthTo, $dayTo ) = split( "-", $enddate);
- if (Date_to_Days($yearFrom,$monthFrom,$dayFrom) > Date_to_Days($yearTo,$monthTo,$dayTo)) {
- return 0;
- # we don't go backwards ( FIXME - handle this error better )
- }
- my $count = 0;
- while (1) {
- ($yearFrom != $yearTo or $monthFrom != $monthTo or $dayFrom != $dayTo) or last; # if they all match, it's the last day
- unless ($self->isHoliday($dayFrom, $monthFrom, $yearFrom)) {
- $count++;
- }
- ($yearFrom, $monthFrom, $dayFrom) = &Date::Calc::Add_Delta_Days($yearFrom, $monthFrom, $dayFrom, 1);
- }
- return($count);
-}
-
1;
__END__