From b7c46cec65ebb25a0397ac18522311d82925cd9c 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). --- 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 6c0a68e..4358137 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 2439127..6030e68 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.1.0