From 844d4d343d35096ad2205e8ce7d35e0a88cdd2f6 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 20 Jan 2015 15:49:39 +0100 Subject: [PATCH] Bug 13601: Add a fallback check for compability with existing code There are a lot of places where the date comes from the DB but the dateformat parameter is not set to 'sql'. dt_from_string needs to fallback with this format if the pref format does not match. --- Koha/DateUtils.pm | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index 61a733f..5fe2653 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -67,6 +67,16 @@ sub dt_from_string { } my $regex; + + # The fallback format is sql/iso + my $fallback_re = qr| + (?\d{4}) + - + (?\d{2}) + - + (?\d{2}) + |xms; + if ( $date_format eq 'metric' ) { # metric format is "dd/mm/yyyy[ hh:mm:ss]" $regex = qr| @@ -88,14 +98,8 @@ sub dt_from_string { |xms; } elsif ( $date_format eq 'iso' or $date_format eq 'sql' ) { - # iso format is yyyy-dd-mm[ hh:mm:ss]" - $regex = qr| - (?\d{4}) - - - (?\d{2}) - - - (?\d{2}) - |xms; + # iso or sql format are yyyy-dd-mm[ hh:mm:ss]" + $regex = $fallback_re; } else { die "Invalid dateformat parameter ($date_format)"; @@ -125,6 +129,15 @@ sub dt_from_string { minute => $+{minute}, second => $+{second}, ); + } elsif ( $date_string =~ $fallback_re ) { + %dt_params = ( + year => $+{year}, + month => $+{month}, + day => $+{day}, + hour => $+{hour}, + minute => $+{minute}, + second => $+{second}, + ); } else { die "The given date ($date_string) does not match the date format ($date_format)"; -- 2.1.0