From 34965273b1854b6cf645f3b53fc6f304922e0c01 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 16 Oct 2019 13:08:23 +0100 Subject: [PATCH] Bug 23382: Truncate dates to minutes for comparison. It's somewhat of a mess in C4::Circulation as to when dates are truncated and when they are not and as such Koha::Charges::Fees could not reliably assume that the dates passed in were consistent with each other. As such, we take the approach of always truncating to the greatest minute smaller than the passed in dates so we are comparing like for like. Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize (cherry picked from commit bbdee010aa192ec0df436a79730343df2b855ff4) Signed-off-by: Lucas Gass --- Koha/Charges/Fees.pm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Koha/Charges/Fees.pm b/Koha/Charges/Fees.pm index cfc053d2d7..9098a29cd0 100644 --- a/Koha/Charges/Fees.pm +++ b/Koha/Charges/Fees.pm @@ -88,9 +88,9 @@ sub new { =cut sub accumulate_rentalcharge { - my ( $self ) = @_; + my ($self) = @_; - my $itemtype = Koha::ItemTypes->find( $self->item->effective_itemtype ); + my $itemtype = Koha::ItemTypes->find( $self->item->effective_itemtype ); my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( { categorycode => $self->patron->categorycode, @@ -101,7 +101,10 @@ sub accumulate_rentalcharge { return 0 unless $issuing_rule; my $units = $issuing_rule->lengthunit; - my $rentalcharge_increment = ( $units eq 'days' ) ? $itemtype->rentalcharge_daily : $itemtype->rentalcharge_hourly; + my $rentalcharge_increment = + ( $units eq 'days' ) + ? $itemtype->rentalcharge_daily + : $itemtype->rentalcharge_hourly; return 0 unless $rentalcharge_increment && $rentalcharge_increment > 0; @@ -110,11 +113,14 @@ sub accumulate_rentalcharge { if ( $units eq 'hours' ) { if ( C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed' ) { - $duration = - $calendar->hours_between( $self->from_date, $self->to_date ); + $duration = $calendar->hours_between( + $self->from_date->truncate( to => 'minute' ), + $self->to_date->truncate( to => 'minute' ) + ); } else { - $duration = $self->to_date->delta_ms($self->from_date); + $duration = $self->to_date->truncate( to => 'minute' ) + ->delta_ms( $self->from_date->truncate( to => 'minute' ) ); } } else { -- 2.39.5