From a3db9a3240de419d0362cbc099eabbb31620cbda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Demians?= Date: Fri, 14 Nov 2014 11:19:17 +0100 Subject: [PATCH] Bug 13242 Add a UT to t/DateUtils.t for testing DateTime bug A bug in DateTime slow down drastically date parsing when the dates are in the far distant future: https://metacpan.org/pod/DateTime#Determining-the-Local-Time-Zone-Can-Be-Slow This UT tests this situation. TO TEST: - Apply the patch containing the UT - prove -v t/DateUtils.t - You see that parsing a 9999-01-01 that take forever (ie more than 1s) - Apply Jonathan patch - prove -v t/DateUtils.t - No more complain. --- t/DateUtils.t | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/t/DateUtils.t b/t/DateUtils.t index 07cd825..dcbf6e4 100755 --- a/t/DateUtils.t +++ b/t/DateUtils.t @@ -3,8 +3,9 @@ use DateTime; use DateTime::TimeZone; use C4::Context; -use Test::More tests => 35; +use Test::More tests => 38; use Test::MockModule; +use Time::HiRes qw/ gettimeofday /; BEGIN { use_ok('Koha::DateUtils'); } @@ -75,6 +76,13 @@ isa_ok( $new_dt, 'DateTime', 'Create DateTime with different timezone' ); cmp_ok( $new_dt->ymd(), 'eq', $testdate_iso, 'Returned Dublin object matches input' ); +for ( qw/ 2014-01-01 2100-01-01 9999-01-01 / ) { + my $duration = gettimeofday(); + $new_dt = dt_from_string($_, 'iso', $dear_dirty_dublin); + $duration = gettimeofday() - $duration; + cmp_ok $duration, '<', 1, "Create DateTime $_ with TZ in less than 1s"; +} + $new_dt = dt_from_string( '2011-06-16 12:00', 'sql' ); isa_ok( $new_dt, 'DateTime', 'Create DateTime from (mysql) sql' ); cmp_ok( $new_dt->ymd(), 'eq', $testdate_iso, 'sql returns correct date' ); @@ -147,3 +155,5 @@ $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)'; + + -- 2.1.2