From dd350655623f509b656332509fe60f5ce8b1b960 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Fri, 5 Aug 2022 15:00:52 +1200 Subject: [PATCH] Bug 6796: Don't add a day if hourly loan period pushes due date If ConsiderLibraryHoursWhenIssuing is set to shorten the loan period to the closing time, if the loan period initially pushes the due date to the following day, the day still gets added when calculating the due date. We simply need to hardcode the due time here as the due day is the same as the issue day. We only need to calculate a due date if ConsiderLibraryHoursWhenIssuing is set to extend the loan period to the next opening day, as we'll need to consider holidays/closed days. Signed-off-by: Sam Lau --- C4/Circulation.pm | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index f69827c8747..5d564e1caed 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3945,15 +3945,13 @@ sub CalcDateDue { if ( $potential_datedue > $library_close and $todayhours->close_time and $tomorrowhours->open_time ) { if ( $considerlibraryhours eq 'close' ) { # datedue will be after the library closes on that day - # shorten loan period to end when library closes - $dur = $potential_datedue->delta_ms( $library_close ); - $sethours = $considerlibraryhours; + # shorten loan period to end when library closes by hardcoding due time + $datedue->set( hour => $close[0], minute => $close[1] ); } elsif ( $considerlibraryhours eq 'open' ) { # datedue will be after the library closes on that day - # extend loan period to when library opens following day - my $library_open = $datedue->clone->set( hour => $open[0], minute => $open[1] ); - $dur = $potential_datedue->delta_ms( $library_open )->add( days => 1 ); - $sethours = $considerlibraryhours; + # extend loan period to when library opens following day by hardcoding due time for next open day + $dur = DateTime::Duration->new( days => 1 ); + $datedue->set( hour => $open[0], minute => $open[1] ); } else { # ignore library open hours $dur = DateTime::Duration->new( hours => $loanlength->{$length_key} ); @@ -3967,16 +3965,10 @@ sub CalcDateDue { $dur = DateTime::Duration->new( days => $loanlength->{$length_key} ); } my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode ); - $datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} ); + $datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} ) if $dur; if ($loanlength->{lengthunit} eq 'days') { $datedue->set_hour(23); $datedue->set_minute(59); - } else { - if ( $sethours and $sethours eq 'close' ) { - $datedue->set( hour => $close[0], minute => $close[1] ); - } elsif ( $sethours and $sethours eq 'open' ) { - $datedue->set( hour => $open[0], minute => $open[1] ); - } } } -- 2.43.0