@@ -, +, @@ you are unable to renew. Both staff client and OPAC user account should display that renewal is allowed exactly one hour after checkout. renewable immediately. (Unless you test less than an hour before midnight) --- C4/Circulation.pm | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2760,13 +2760,18 @@ sub CanBookBeRenewed { if ( defined $issuingrule->{norenewalbefore} ) { - # Get current time and add norenewalbefore. - # If this is smaller than date_due, it's too soon for renewal. - if ( - DateTime->now( time_zone => C4::Context->tz() )->add( - $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} - ) < $itemissue->{date_due} - ) + # Calculate soonest renewal by subtracting 'No renewal before' from due date + my $soonestrenewal = + $itemissue->{date_due}->clone() + ->subtract( + $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} ); + + # Depending on syspref reset the exact time, only check the date + if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' ) { + $soonestrenewal->truncate( to => 'day' ); + } + + if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) ) { return ( 0, "auto_too_soon" ) if $itemissue->{auto_renew}; return ( 0, "too_soon" ); @@ -3001,11 +3006,14 @@ sub GetSoonestRenewDate { if ( defined $issuingrule->{norenewalbefore} ) { my $soonestrenewal = - $itemissue->{date_due}->subtract( + $itemissue->{date_due}->clone() + ->subtract( $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} ); - $soonestrenewal = $now > $soonestrenewal ? $now : $soonestrenewal; - return $soonestrenewal; + if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' ) { + $soonestrenewal->truncate( to => 'day' ); + } + return $soonestrenewal if $now < $soonestrenewal; } return $now; } --