From f63aaf22429eb77de08e2efa15c9ffe479fadde7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 26 Nov 2014 09:41:36 +0100 Subject: [PATCH] Bug 13242: Remove warning if no parameter given Without any parameter, dt_from_string should not raise a warning message. Test plan: Verify that the test file t/DateUtils.t displays a warning: Use of uninitialized value $date_string in pattern match (m//) at Koha/DateUtils.pm line 58 if the change in dt_from_string is not applied (manually edit the file). Signed-off-by: Tomas Cohen Arazi --- Koha/DateUtils.pm | 2 +- t/DateUtils.t | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index 6c0a68e5ba..43581378b5 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -56,7 +56,7 @@ sub dt_from_string { # FIXME: see bug 13242 => no TZ for dates 'infinite' return DateTime::Format::DateParse->parse_datetime($date_string) - if $date_string =~ /^9999-/; + if $date_string and $date_string =~ /^9999-/; if ( !$tz ) { $tz = C4::Context->tz; diff --git a/t/DateUtils.t b/t/DateUtils.t index 2439127fcb..6030e685d0 100755 --- a/t/DateUtils.t +++ b/t/DateUtils.t @@ -3,7 +3,7 @@ use DateTime; use DateTime::TimeZone; use C4::Context; -use Test::More tests => 41; +use Test::More tests => 42; use Test::MockModule; use Time::HiRes qw/ gettimeofday /; @@ -159,3 +159,6 @@ $date_string = output_pref({ dt => $dt, dateformat => 'metric', timeformat => '2 cmp_ok $date_string, 'eq', '11/12/2013 18:35', 'as_due_date with hours and timeformat 24hr (non-midnight time)'; $date_string = output_pref({ dt => $dt, dateformat => 'us', timeformat => '12hr', as_due_date => 1 }); cmp_ok $date_string, 'eq', '12/11/2013 06:35 PM', 'as_due_date with hours and timeformat 12hr (non-midnight time)'; + +my $now = DateTime->now; +is( dt_from_string, $now, "Without parameter, dt_from_string should return today" ); -- 2.39.5