From 1b742b04372b68d7da93b21335f932f9f6fabcd4 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Fri, 8 Nov 2019 13:37:17 +0000
Subject: [PATCH] Bug 23974: (follow-up) Add same day loan tests

Hourly loans can be short enough to not cross a day boundary and as such
we should test for that scenario in the hour_between tests too.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
---
 t/db_dependent/Calendar.t | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/t/db_dependent/Calendar.t b/t/db_dependent/Calendar.t
index e3e82b5e1f..22f481c5b7 100644
--- a/t/db_dependent/Calendar.t
+++ b/t/db_dependent/Calendar.t
@@ -150,12 +150,18 @@ subtest 'hours_between | days_between' => sub {
 
         subtest 'Different hours' => sub {
 
-            plan tests => 8;
+            plan tests => 10;
+
+            # Between 5th and 5th (Same day short hours loan)
+            my $diff_hours = $calendar->hours_between( $now, $now->clone->add(hours => 3) )->hours;
+            is( $diff_hours, 3, '' );
+            my $diff_days = $calendar->days_between( $now, $now->clone->add(hours => 3) )->delta_days;
+            is( $diff_days, 0, '' );
 
             # Between 5th and 6th
-            my $diff_hours = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) )->hours;
+            $diff_hours = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) )->hours;
             is( $diff_hours, 1 * 24 - 3, '' );
-            my $diff_days = $calendar->days_between( $now, $nov_6->clone->subtract(hours => 3) )->delta_days;
+            $diff_days = $calendar->days_between( $now, $nov_6->clone->subtract(hours => 3) )->delta_days;
             is( $diff_days, 1, '' );
 
             # Between 5th and 7th
@@ -233,6 +239,9 @@ subtest 'hours_between | days_between' => sub {
 
             my ( $diff_hours, $diff_days );
 
+            # Between 5th and 5th (Same day short hours loan)
+            # No test - one cannot issue on a holiday and we do not yet record opening hours to take those into account
+
             # Between 5th and 6th
             my $duration = $calendar->hours_between( $now, $nov_6->clone->subtract(hours => 3) );
             is( $duration->hours, abs(0 * 24 - 3), '' ); # FIXME $duration->hours always return a abs
-- 
2.11.0