From a1ba1f134d216d8c1dcf58fedb390f38d6994561 Mon Sep 17 00:00:00 2001
From: Aleisha Amohia <aleishaamohia@hotmail.com>
Date: Tue, 25 Feb 2020 00:28:36 +0000
Subject: [PATCH] Bug 24718: Ensuring tests pass

Confirm these tests pass before and after applying patches

t/db_dependent/Holds.t
t/db_dependent/Circulation.t
t/db_dependent/Circulation/issue.t
t/db_dependent/Holds/HoldFulfillmentPolicy.t
t/db_dependent/Holds/LocalHoldsPriority.t
t/db_dependent/Holds/HoldItemtypeLimit.t
t/db_dependent/Holds/RevertWaitingStatus.t
t/db_dependent/HoldsQueue.t
t/db_dependent/Reserves/CancelExpiredReserves.t

Signed-off-by: David Nind <david@davidnind.com>
---
 C4/HoldsQueue.pm       | 4 ++--
 C4/Reserves.pm         | 8 ++++++--
 Koha/Item.pm           | 2 +-
 t/db_dependent/Holds.t | 4 ++--
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm
index 339156a5eb..7f0c07a619 100755
--- a/C4/HoldsQueue.pm
+++ b/C4/HoldsQueue.pm
@@ -239,7 +239,7 @@ sub GetBibsWithPendingHoldRequests {
                      FROM reserves
                      WHERE found IS NULL
                      AND priority > 0
-                     AND reservedate <= CURRENT_DATE()
+                     AND reservedate <= CURRENT_TIMESTAMP()
                      AND suspend = 0
                      ";
     my $sth = $dbh->prepare($bib_query);
@@ -283,7 +283,7 @@ sub GetPendingHoldRequestsForBib {
                          WHERE biblionumber = ?
                          AND found IS NULL
                          AND priority > 0
-                         AND reservedate <= CURRENT_DATE()
+                         AND reservedate <= CURRENT_TIMESTAMP()
                          AND suspend = 0
                          ORDER BY priority";
     my $sth = $dbh->prepare($request_query);
diff --git a/C4/Reserves.pm b/C4/Reserves.pm
index 00de5702ec..5d50789edf 100644
--- a/C4/Reserves.pm
+++ b/C4/Reserves.pm
@@ -436,9 +436,13 @@ sub CanItemBeReserved {
         return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
     }
 
+    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
+    my $fromdate = dt_from_string->set({ hour => 00, minute => 00, second => 00 });
+    my $todate = dt_from_string->set({ hour => 23, minute => 59, second => 59 });
+
     my $today_holds = Koha::Holds->search({
         borrowernumber => $borrowernumber,
-        reservedate    => dt_from_string->date
+        reservedate    => [ -and => { '>=' => $dtf->format_datetime($fromdate) }, { '<=' => $dtf->format_datetime($todate) } ]
     });
 
     if (   defined $holds_per_day && $holds_per_day ne ''
@@ -905,7 +909,7 @@ sub CancelExpiredReserves {
     my $expireWaiting = C4::Context->preference('ExpireReservesMaxPickUpDelay');
 
     my $dtf = Koha::Database->new->schema->storage->datetime_parser;
-    my $params = { expirationdate => { '<', $today } };
+    my $params = { expirationdate => { '<', $dtf->format_datetime($today) } };
     $params->{found} = [ { '!=', 'W' }, undef ]  unless $expireWaiting;
 
     # FIXME To move to Koha::Holds->search_expired (?)
diff --git a/Koha/Item.pm b/Koha/Item.pm
index 9560a567cb..27d5a51b2a 100644
--- a/Koha/Item.pm
+++ b/Koha/Item.pm
@@ -629,7 +629,7 @@ sub current_holds {
         itemnumber => $self->itemnumber,
         suspend => 0,
         -or => [
-            reservedate => { '<=' => $dtf->format_date(dt_from_string) },
+            reservedate => { '<=' => $dtf->format_datetime(dt_from_string) },
             waitingdate => { '!=' => undef },
         ],
     };
diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t
index 688b12f2dd..be8e96c462 100755
--- a/t/db_dependent/Holds.t
+++ b/t/db_dependent/Holds.t
@@ -100,7 +100,7 @@ my $reservedate = $first_hold->reservedate;
 my $borrowernumber = $first_hold->borrowernumber;
 my $branch_1code = $first_hold->branchcode;
 my $reserve_id = $first_hold->reserve_id;
-is( $reservedate, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), "holds_placed_today should return a valid reserve date");
+is( dt_from_string( $reservedate ), dt_from_string, "holds_placed_today should return a valid reserve date");
 is( $borrowernumber, $borrowernumbers[0], "holds_placed_today should return a valid borrowernumber");
 is( $branch_1code, $branch_1, "holds_placed_today should return a valid branchcode");
 ok($reserve_id, "Test holds_placed_today()");
@@ -709,7 +709,7 @@ subtest 'CanItemBeReserved / holds_per_day tests' => sub {
     is_deeply(
         CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
         { status => 'tooManyReservesToday', limit => 2 },
-        'Patron cannot a third item with 2 reserves daily cap'
+        'Patron cannot reserve a third item with 2 reserves daily cap'
     );
 
     # Update last hold so reservedate is in the past, so 2 holds, but different day
-- 
2.11.0