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 which affects Koha::DateUtils function dt_from_string() and output_pref(). 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 the patch containing the fix - prove -v t/DateUtils.t - No more complain. Followed test plan. Test behaves as expected. Signed-off-by: Marc Véron <veron@veron.ch> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Works as described - check-ins are now much faster. Passes tests and QA script. Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
parent
0a41d247b5
commit
e2a169dc9d
|
|
@ -1,12 +1,11 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use 5.010;
|
||||
use Modern::Perl;
|
||||
use DateTime;
|
||||
use DateTime::TimeZone;
|
||||
|
||||
use C4::Context;
|
||||
use Test::More tests => 34;
|
||||
use Test::More tests => 41;
|
||||
use Test::MockModule;
|
||||
use Time::HiRes qw/ gettimeofday /;
|
||||
|
||||
BEGIN { use_ok('Koha::DateUtils'); }
|
||||
|
||||
|
|
@ -77,6 +76,17 @@ 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 dt_from_string() for $_ with TZ in less than 1s";
|
||||
$duration = gettimeofday();
|
||||
output_pref( { dt => $new_dt } );
|
||||
$duration = gettimeofday() - $duration;
|
||||
cmp_ok $duration, '<', 1, "Create DateTime with output_pref() for $_ 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' );
|
||||
|
|
@ -106,6 +116,10 @@ cmp_ok( $dt0->ymd(), 'eq', $ymd, 'Returned object corrects iso day 0' );
|
|||
$dt0 = dt_from_string( '0000-00-00', 'iso' );
|
||||
is( $dt0, undef, "undefined returned for 0 iso date" );
|
||||
|
||||
# Return undef if passed mysql 9999-* date
|
||||
my $dt9999 = dt_from_string( '9999-12-31' );
|
||||
is( $dt9999->ymd(), '9999-12-31', "dt_from_string should return a DateTime object for 9999-12-31" );
|
||||
|
||||
my $formatted = format_sqldatetime( '2011-06-16 12:00:07', 'metric', '24hr' );
|
||||
cmp_ok( $formatted, 'eq', '16/06/2011 12:00', 'format_sqldatetime conversion' );
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue