From: Dan Scott Date: Mon, 8 Oct 2012 15:25:41 +0000 (-0400) Subject: TPAC: Invalid due dates cause 500 server error X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=09a85ef0dddb9bf05bff352b4b4bccfb219ee8c1;p=evergreen%2Fpines.git TPAC: Invalid due dates cause 500 server error CStore appears to return dates with leading 0s (such as '0212-10-08 23:59:59-05:17:32') with the leading 0s stripped off, resulting in cases with 1-digit or 3-digit years for which DateTime::Format::ISO8601 returns an error. We can protect against this problem by adding some defensive code to the TPAC utility method to add the 0s back to the start of the year. We can also log the problem when it occurs so that administrators can fix the problem dates in the database. Signed-off-by: Dan Scott Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index e7e3bd138e..04360af1dd 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -182,7 +182,22 @@ sub init_ro_object_cache { # turns an ISO date into something TT can understand $ro_object_subs->{parse_datetime} = sub { my $date = shift; - $date = DateTime::Format::ISO8601->new->parse_datetime(cleanse_ISO8601($date)); + + # Probably an accidental entry like '0212' instead of '2012', + # but 1) the leading 0 gets stripped in CStoreEditor and + # 2) DateTime::Format::ISO8601 returns an error as years + # must be 2 or 4 digits + if ($date =~ m/^\d{3}-/) { + $logger->warn("Invalid date had a 3-digit year: $date"); + $date = '0' . $date; + } elsif ($date =~ m/^\d{1}-/) { + $logger->warn("Invalid date had a 1-digit year: $date"); + $date = '000' . $date; + } + + my $cleansed_date = cleanse_ISO8601($date); + + $date = DateTime::Format::ISO8601->new->parse_datetime($cleansed_date); return sprintf( "%0.2d:%0.2d:%0.2d %0.2d-%0.2d-%0.4d", $date->hour,