Browse Source

Bug 25802: Change addDate to addDuration

1. Check using git grep command that addDate does not exist
2. Check the patch that addDuration is spelt right
3. Check that tests pass t/Calendar.t

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.05.x
Eden Bacani 3 years ago
committed by Jonathan Druart
parent
commit
e2379b5797
  1. 6
      C4/Circulation.pm
  2. 10
      Koha/Calendar.pm
  3. 2
      Koha/Checkouts.pm
  4. 40
      t/Calendar.t

6
C4/Circulation.pm

@ -1345,7 +1345,7 @@ sub checkHighHolds {
} else {
$duration = C4::Context->preference('decreaseLoanHighHoldsDuration');
}
my $reduced_datedue = $calendar->addDate( $issuedate, $duration );
my $reduced_datedue = $calendar->addDuration( $issuedate, $duration );
$reduced_datedue->set_hour($orig_due->hour);
$reduced_datedue->set_minute($orig_due->minute);
$reduced_datedue->truncate( to => 'minute' );
@ -2466,7 +2466,7 @@ sub _calculate_new_debar_dt {
branchcode => $branchcode,
days_mode => 'Calendar'
);
$new_debar_dt = $calendar->addDate( $return_date, $suspension_days );
$new_debar_dt = $calendar->addDuration( $return_date, $suspension_days );
}
else {
$new_debar_dt = $return_date->clone()->add_duration($suspension_days);
@ -3651,7 +3651,7 @@ sub CalcDateDue {
$dur = DateTime::Duration->new( days => $loanlength->{$length_key});
}
my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode );
$datedue = $calendar->addDate( $datedue, $dur, $loanlength->{lengthunit} );
$datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} );
if ($loanlength->{lengthunit} eq 'days') {
$datedue->set_hour(23);
$datedue->set_minute(59);

10
Koha/Calendar.pm

@ -90,11 +90,11 @@ sub _holidays {
return $holidays // {};
}
sub addDate {
sub addDuration {
my ( $self, $startdate, $add_duration, $unit ) = @_;
Koha::Exceptions::MissingParameter->throw("Missing mandatory option for Koha:Calendar->addDate: days_mode")
Koha::Exceptions::MissingParameter->throw("Missing mandatory option for Koha:Calendar->addDuration: days_mode")
unless exists $self->{days_mode};
# Default to days duration (legacy support I guess)
@ -392,7 +392,7 @@ Koha::Calendar - Object containing a branches calendar
# are we open
$open = $c->is_holiday($dt);
# when will item be due if loan period = $dur (a DateTime::Duration object)
$duedate = $c->addDate($dt,$dur,'days');
$duedate = $c->addDuration($dt,$dur,'days');
=head1 DESCRIPTION
@ -408,9 +408,9 @@ my $calendar = Koha::Calendar->new( branchcode => 'MAIN' );
The option branchcode is required
=head2 addDate
=head2 addDuration
my $dt = $calendar->addDate($date, $dur, $unit)
my $dt = $calendar->addDuration($date, $dur, $unit)
C<$date> is a DateTime object representing the starting date of the interval.

2
Koha/Checkouts.pm

@ -57,7 +57,7 @@ sub calculate_dropbox_date {
);
my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
my $today = dt_from_string;
my $dropbox_date = $calendar->addDate( $today, -1 );
my $dropbox_date = $calendar->addDuration( $today, -1 );
return $dropbox_date;
}

40
t/Calendar.t

@ -133,7 +133,7 @@ my $day_after_christmas = DateTime->new(
year => 2012,
month => 12,
day => 26
); # for testing negative addDate
); # for testing negative addDuration
my $holiday_for_another_branch = DateTime->new(
year => 2012,
@ -218,23 +218,23 @@ my $holiday_excepted = DateTime->new(
$cal = Koha::Calendar->new( branchcode => 'MPL', days_mode => 'Datedue' );
is($cal->addDate( $dt, $one_day_dur, 'days' ), # tuesday
is($cal->addDuration( $dt, $one_day_dur, 'days' ), # tuesday
dt_from_string('2012-07-05','iso'),
'Single day add (Datedue, matches holiday, shift)' );
is($cal->addDate( $dt, $two_day_dur, 'days' ),
is($cal->addDuration( $dt, $two_day_dur, 'days' ),
dt_from_string('2012-07-05','iso'),
'Two days add, skips holiday (Datedue)' );
cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ), 'eq',
cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
'2012-07-30T11:53:00',
'Add 7 days (Datedue)' );
is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
'addDate skips closed Sunday (Datedue)' );
is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
'addDuration skips closed Sunday (Datedue)' );
is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
'Negative call to addDate (Datedue)' );
is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
'Negative call to addDuration (Datedue)' );
## Note that the days_between API says closed days are not considered.
## This tests are here as an API test.
@ -251,19 +251,19 @@ my $holiday_excepted = DateTime->new(
$dt = dt_from_string('2012-07-03','iso');
is($cal->addDate( $dt, $one_day_dur, 'days' ),
is($cal->addDuration( $dt, $one_day_dur, 'days' ),
dt_from_string('2012-07-05','iso'),
'Single day add (Calendar)' );
cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ), 'eq',
cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
'2012-08-01T11:53:00',
'Add 7 days (Calendar)' );
is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
'addDate skips closed Sunday (Calendar)' );
is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
'addDuration skips closed Sunday (Calendar)' );
is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
'Negative call to addDate (Calendar)' );
is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
'Negative call to addDuration (Calendar)' );
cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
'==', 40, 'days_between calculates correctly (Calendar)' );
@ -279,19 +279,19 @@ my $holiday_excepted = DateTime->new(
$dt = dt_from_string('2012-07-03','iso');
is($cal->addDate( $dt, $one_day_dur, 'days' ),
is($cal->addDuration( $dt, $one_day_dur, 'days' ),
dt_from_string('2012-07-04','iso'),
'Single day add (Days)' );
cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ),'eq',
cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ),'eq',
'2012-07-30T11:53:00',
'Add 7 days (Days)' );
is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 7,
'addDate doesn\'t skip closed Sunday (Days)' );
is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 7,
'addDuration doesn\'t skip closed Sunday (Days)' );
is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-25',
'Negative call to addDate (Days)' );
is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-25',
'Negative call to addDuration (Days)' );
## Note that the days_between API says closed days are not considered.
## This tests are here as an API test.

Loading…
Cancel
Save