From dff7f788deca84f96fd71641cef6fb05431eb5ff Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 31 Aug 2017 14:35:55 +0200 Subject: [PATCH] Bug 19222: Why does dt_from_string not understand yyyy-mm-ddThh:mm:ss? dt_from_string disregards the time part when there is a T before it. But note that if you print a datetime it actually prints that T. Like: 2017-08-31T13:32:37 A small regex adjustment could be helpful. Test plan: Run t/DateUtils.t Signed-off-by: Marcel de Rooy Signed-off-by: Mark Tompsett --- Koha/DateUtils.pm | 2 +- t/DateUtils.t | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index af5ce7e..6ce3dab 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -115,7 +115,7 @@ sub dt_from_string { # Add the faculative time part [hh:mm[:ss]] my $time_re .= qr| ( - \s* + \s*(T\s*)? (?\d{2}) : (?\d{2}) diff --git a/t/DateUtils.t b/t/DateUtils.t index 884990b..7488dfa 100755 --- a/t/DateUtils.t +++ b/t/DateUtils.t @@ -4,7 +4,7 @@ use DateTime::TimeZone; use C4::Context; -use Test::More tests => 63; +use Test::More tests => 66; use Test::MockModule; use Test::Warn; @@ -224,6 +224,14 @@ is( output_pref( { dt => $dt, dateonly => 1 } ), '01/01/1900', 'dt_from_string s $dt = dt_from_string('2015-01-31 01:02:03'); is( output_pref( {dt => $dt} ), '31/01/2015 01:02', 'dt_from_string should fallback to sql format' ); +# When T prefixes the time (like printing a datetime) +$dt = dt_from_string('2015-01-31T13:14:15'); +is( $dt->hour, 13, 'Check hour from dt_from_string with T' ); +$dt = dt_from_string('2015-01-31 T13:14:15'); +is( $dt->minute, 14, 'Check minute from dt_from_string with \sT' ); +$dt = dt_from_string('2015-01-31 T 13:14:15'); +is( $dt->second, 15, 'Check second from dt_from_string with \sT\s' ); + # output_pref with no parameters, single parameter (no hash) is( output_pref(), undef, 'Call output_pref without parameters' ); try { -- 2.1.4