From 090f2885b7a910ee84212fa5bb0141611121eb77 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Mon, 12 Dec 2016 16:49:44 +0200 Subject: [PATCH] Bug 16387: Fix default shortened loan period time When a loan period is shortened due to using decreaseLoanHighHolds* the time is always set to the current time in X days, even if the original loan period is given in days and not in hours. It should default to 23:59 as is normal for loan periods given in days. As original due date time defaults to 23:59 when given in days, this patch modifies the hours and minutes of shortened due date to be equal to original due date. To test: 1. prove t/db_dependent/DecreaseLoanHighHolds.t Signed-off-by: Grace McKenzie Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall (cherry picked from commit 21ac9fcdc2ca449a491cc79e68cc854ee248d911) Signed-off-by: Katrin Fischer --- C4/Circulation.pm | 3 +++ t/db_dependent/DecreaseLoanHighHolds.t | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index be50318293..f25bcc11ab 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1213,6 +1213,9 @@ sub checkHighHolds { my $decreaseLoanHighHoldsDuration = C4::Context->preference('decreaseLoanHighHoldsDuration'); my $reduced_datedue = $calendar->addDate( $issuedate, $decreaseLoanHighHoldsDuration ); + $reduced_datedue->set_hour($orig_due->hour); + $reduced_datedue->set_minute($orig_due->minute); + $reduced_datedue->truncate( to => 'minute' ); if ( DateTime->compare( $reduced_datedue, $orig_due ) == -1 ) { $return_data->{exceeded} = 1; diff --git a/t/db_dependent/DecreaseLoanHighHolds.t b/t/db_dependent/DecreaseLoanHighHolds.t index b6a175c739..d4faaa3317 100755 --- a/t/db_dependent/DecreaseLoanHighHolds.t +++ b/t/db_dependent/DecreaseLoanHighHolds.t @@ -27,7 +27,7 @@ use Koha::Hold; use t::lib::TestBuilder; use t::lib::Mocks; -use Test::More tests => 14; +use Test::More tests => 17; my $dbh = C4::Context->dbh; my $schema = Koha::Database->new()->schema(); @@ -104,6 +104,13 @@ $builder->build( my $item = pop(@items); my $patron = pop(@patrons); +my $orig_due = C4::Circulation::CalcDateDue( + DateTime->now(time_zone => C4::Context->tz()), + $item->effective_itemtype, + $patron->branchcode, + $patron->unblessed +); + t::lib::Mocks::mock_preference( 'decreaseLoanHighHolds', 1 ); t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsDuration', 1 ); t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsValue', 1 ); @@ -119,6 +126,11 @@ is( $data->{outstanding}, 6, "Should have 5 outstanding holds" ); is( $data->{duration}, 1, "Should have duration of 1" ); is( ref( $data->{due_date} ), 'DateTime', "due_date should be a DateTime object" ); +my $duedate = $data->{due_date}; +is($duedate->hour, $orig_due->hour, 'New due hour is equal to original due hour.'); +is($duedate->min, $orig_due->min, 'New due minute is equal to original due minute.'); +is($duedate->sec, 0, 'New due date second is zero.'); + t::lib::Mocks::mock_preference( 'decreaseLoanHighHoldsControl', 'dynamic' ); $data = C4::Circulation::checkHighHolds( $item_hr, $patron_hr ); is( $data->{exceeded}, 0, "Should not exceed threshold" ); -- 2.39.5