Bug 5549 : Koha::Calendar::addDate should not loop on -1

Control variable of loop should be absolute value
to avoid looping when backtracking
This commit is contained in:
Colin Campbell 2011-06-24 14:28:22 +01:00 committed by Chris Cormack
parent 1d62ea2c9f
commit e012957186
2 changed files with 6 additions and 2 deletions

View File

@ -87,6 +87,7 @@ sub addDate {
if ( ref $add_duration ne 'DateTime::Duration' ) {
$add_duration = DateTime::Duration->new( days => $add_duration );
}
$unit ||= q{}; # default days ?
my $days_mode = $self->{days_mode};
Readonly::Scalar my $return_by_hour => 10;
my $day_dur = DateTime::Duration->new( days => 1 );
@ -114,7 +115,7 @@ sub addDate {
}
} else {
my $days = $add_duration->in_units('days');
my $days = abs $add_duration->in_units('days');
while ($days) {
$base_date->add_duration($day_dur);
if ( $self->is_holiday($base_date) ) {

View File

@ -5,7 +5,7 @@ use DateTime;
use DateTime::TimeZone;
use C4::Context;
use Test::More tests => 8; # last test to print
use Test::More tests => 9;
BEGIN { use_ok('Koha::Calendar'); }
@ -57,3 +57,6 @@ is( $cal->is_holiday($notspecial), 0, 'open day test' );
my $dt = $cal->addDate( $saturday, 1, 'days' );
is( $dt->day_of_week, 1, 'addDate skips closed Sunday' );
$dt = $cal->addDate( $bloomsday, -1 );
cmp_ok( $dt->ymd(), 'cmp', '2011-06-15', 'Negative call to addDate' );