From 58cc95a372e0cf7f3b6832f5256f23d6dd0fcb26 Mon Sep 17 00:00:00 2001 From: Lyon3 Team Date: Mon, 2 Jul 2012 10:02:36 +0200 Subject: [PATCH] Patrons get incorrectly debarred Content-Type: text/plain; charset="utf-8" http://koha-community.org Patrons get incorrectly debarred because of the use of Datetime->delta_days wich happens to always return a positive number. Added a check to inverse the delta when patron is not late. Also changed the use of Datetime->truncate function so it follows the docs, using 'day' instead of 'days' (which is used in DateTime::Duration). http://bugs.koha-community.org/show_bug.cgi?id=8251 Signed-off-by: Tajoli Zeno --- Koha/Calendar.pm | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index ac3655a..1c4c879 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -176,10 +176,15 @@ sub days_between { $datestart_temp->truncate( to => 'day' ); $dateend_temp->truncate( to => 'day' ); my $duration = $dateend_temp - $datestart_temp; - while ( DateTime->compare( $datestart_temp, $dateend_temp ) == -1 ) { - $datestart_temp->add( days => 1 ); - if ( $self->is_holiday($datestart_temp) ) { - $duration->subtract( days => 1 ); + # if borrower is not late, delta days must be negative + if(DateTime->compare( $start_dt, $end_dt ) > -1){ + $duration = $duration->inverse; + } else { + while ( DateTime->compare( $datestart_temp, $dateend_temp ) == -1 ) { + $datestart_temp->add( days => 1 ); + if ( $self->is_holiday($datestart_temp) ) { + $duration->subtract( days => 1 ); + } } } return $duration; -- 1.7.2.5