Bug 8391: prevent error when viewing circ history with bad dates
authorRobin Sheat <robin@catalyst.net.nz>
Fri, 27 Jul 2012 09:34:17 +0000 (11:34 +0200)
committerPaul Poulain <paul.poulain@biblibre.com>
Mon, 3 Sep 2012 13:38:38 +0000 (15:38 +0200)
Sometime the circ history will contain "0000-00-00" as a returndate when
an item was lost rather than returned. This currently causes an error
when attempting to parse the dates, this patch causes an empty string to
be returned instead.

Note: a future enhancement should distinguish between "no date provided"
and "invalid date provided" to allow distinctions to be made.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
Koha/DateUtils.pm

index d7892dd..b2c1df8 100644 (file)
@@ -80,6 +80,7 @@ sub dt_from_string {
             } elsif ( $date_format eq 'sql' ) {
                 $date_string =~
 s/(\d{4})(\d{2})(\d{2})\s+(\d{2})(\d{2})(\d{2})/$1-$2-$3T$4:$5:$6/;
+                return if ($date_string =~ /^0000-00-00/);
                 $date_string =~ s/00T/01T/;
             }
         }
@@ -162,6 +163,7 @@ sub format_sqldatetime {
     my $force_pref = shift;    # if testing we want to override Context
     if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) {
         my $dt = dt_from_string( $str, 'sql' );
+        return q{} unless $dt;
         $dt->truncate( to => 'minute' );
         return output_pref( $dt, $force_pref );
     }