From 4812692ca9fa57124f72f2aad82da4b5e3a8d723 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Thu, 9 Apr 2020 12:36:04 +0200
Subject: [PATCH] Bug 25088: prevent too many datetime operations

dropping this now to not forget, but it's not super useful.

Note for myself: no sure about the removal of $new_hard_due_date->clone
in the sub
---
 .../en/modules/tools/batch_extend_due_dates.tt   |  2 +-
 tools/batch_extend_due_dates.pl                  | 16 +++++++++-------
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_extend_due_dates.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_extend_due_dates.tt
index e572b2b3d7..81bece45fe 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_extend_due_dates.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_extend_due_dates.tt
@@ -134,7 +134,7 @@
                                                 <td>[% checkout.issuedate | $KohaDates %]</td>
                                                 <td>[% Branches.GetName( checkout.branchcode ) | html %]</td>
                                                 <td>
-                                                    [% new_due_dates.shift | $KohaDates as_due_date => 1 %]
+                                                    [% new_due_dates.shift %]
                                                 </td>
                                             </tr>
                                         [% END %]
diff --git a/tools/batch_extend_due_dates.pl b/tools/batch_extend_due_dates.pl
index 572e57bdc9..04e24d36bf 100755
--- a/tools/batch_extend_due_dates.pl
+++ b/tools/batch_extend_due_dates.pl
@@ -53,6 +53,8 @@ elsif ( $op eq 'list' ) {
     my $due_date_days     = $input->param('due_date_days');
 
     $new_hard_due_date &&= dt_from_string($new_hard_due_date);
+    $from_due_date     &&= dt_from_string($from_due_date);
+    $to_due_date       &&= dt_from_string($to_due_date);
 
     my $dtf = Koha::Database->new->schema->storage->datetime_parser;
     my $search_params;
@@ -63,7 +65,7 @@ elsif ( $op eq 'list' ) {
         $search_params->{'me.branchcode'} = { -in => \@branchcodes };
     }
     if ( $from_due_date and $to_due_date ) {
-        my $to_due_date_endday = dt_from_string($to_due_date);
+        my $to_due_date_endday = $to_due_date;
         $to_due_date_endday
           ->set(  # We set last second of day to see all checkouts from that day
             hour   => 23,
@@ -72,17 +74,17 @@ elsif ( $op eq 'list' ) {
           );
         $search_params->{'me.date_due'} = {
             -between => [
-                $dtf->format_datetime( dt_from_string($from_due_date) ),
+                $dtf->format_datetime($from_due_date),
                 $dtf->format_datetime($to_due_date_endday),
             ]
         };
     }
     elsif ($from_due_date) {
         $search_params->{'me.date_due'} =
-          { '>=' => $dtf->format_datetime( dt_from_string($from_due_date) ) };
+          { '>=' => $dtf->format_datetime($from_due_date) };
     }
     elsif ($to_due_date) {
-        my $to_due_date_endday = dt_from_string($to_due_date);
+        my $to_due_date_endday = $to_due_date;
         $to_due_date_endday
           ->set(  # We set last second of day to see all checkouts from that day
             hour   => 23,
@@ -109,7 +111,7 @@ elsif ( $op eq 'list' ) {
                 new_hard_due_date => $new_hard_due_date,
                 add_days          => $due_date_days
             }
-          ), dateformat => 'iso' });
+          ), as_due_date => 1 });
     }
 
     $template->param(
@@ -162,13 +164,13 @@ sub calc_new_due_date {
 
     my $new;
     if ( $new_hard_due_date ) {
-      $new = $new_hard_due_date->clone->set(
+      $new = $new_hard_due_date->set(
         hour   => $due_date->hour,
         minute => $due_date->minute,
         second => $due_date->second,
       )
   } else {
-      $new = $due_date->clone->add( days => $add_days );
+      $new = $due_date->add( days => $add_days );
   }
   return $new;
 }
-- 
2.20.1