From c4c6c326c25973b66e8439c83ba609121957e14e Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Thu, 13 Nov 2014 09:34:43 +0100
Subject: [PATCH] Bug 13242: DateUtils should manage separately 9999-* dates

On bug 13226, we have seen that
my $date = DateTime->new(year => 9999, month => 12, day => 31);
 => OK

DateTime::Format::DateParse->parse_datetime( '9999-12-31' );
 => OK

DateTime::Format::DateParse->parse_datetime( '9999-12-31',
 'America/Los_Angeles' );
 => KO (~20sec on my laptop)

For instance if you try to check in items for a patron which is
restricted indefinitely (and there is no overdue on the item), the code
in C4::Circulation::AddReturn l~1948
  my $borrower_debar_dt = dt_from_string( $borrower->{debarred} );
will be called.

dt_from_string should not called
DateTime::Format::DateParse->parse_datetime with the time zone parameter
in this case.

Test plan:
Create an indefinitely restriction for a patron and check an item in.
Without this patch, it should take ~20 sec.
With, ~2 or 3 sec.
---
 Koha/DateUtils.pm | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm
index b372a3a..2a3543e 100644
--- a/Koha/DateUtils.pm
+++ b/Koha/DateUtils.pm
@@ -53,6 +53,11 @@ to the system preferences. If the date string is empty DateTime->now is returned
 
 sub dt_from_string {
     my ( $date_string, $date_format, $tz ) = @_;
+
+    if ( $date_string =~ /^9999-/ ) {
+        return DateTime::Format::DateParse->parse_datetime($date_string);
+    }
+
     if ( !$tz ) {
         $tz = C4::Context->tz;
     }
-- 
2.1.0