From 888a97f15b3c1c6f89311c726793c6cab14850b4 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Mon, 30 Oct 2017 14:41:47 +0000 Subject: [PATCH] Bug 19176: Fix how t::lib::Dates::compare handle timezone Signed-off-by: Jonathan Druart Signed-off-by: Jonathan Druart --- t/Test/Dates.t | 11 +++++++---- t/lib/Dates.pm | 2 -- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/t/Test/Dates.t b/t/Test/Dates.t index 78206e2fc0..4857e278c5 100644 --- a/t/Test/Dates.t +++ b/t/Test/Dates.t @@ -1,5 +1,5 @@ use Modern::Perl; -use Test::More tests => 7; +use Test::More tests => 8; use t::lib::Dates; use Koha::DateUtils qw( dt_from_string ); @@ -20,7 +20,10 @@ is( t::lib::Dates::compare( $dt_1, $dt_3 ), is( t::lib::Dates::compare( $dt_3, $dt_1 ), 0, 'If there is less than 1min, the dates are considered identicals' ); -$dt_1->set_time_zone('+0000'); -$dt_3 = $dt_1->clone->set_time_zone('+0400'); +$dt_1 = DateTime->new(year => 2001, month => 1, day => 1, hour => 0, minute => 0, second => 0, time_zone => '+0000'); +$dt_3 = DateTime->new(year => 2001, month => 1, day => 1, hour => 4, minute => 0, second => 0, time_zone => '+0400'); +is( t::lib::Dates::compare( $dt_1, $dt_3 ), 0, 'Different timezone but same date/time' ); -is( t::lib::Dates::compare( $dt_1, $dt_3 ), -1, "Compare different timezones" ); +$dt_1 = DateTime->new(year => 2001, month => 1, day => 1, hour => 0, minute => 0, second => 0, time_zone => '+0000'); +$dt_3 = DateTime->new(year => 2001, month => 1, day => 1, hour => 0, minute => 0, second => 0, time_zone => '+0400'); +is( t::lib::Dates::compare( $dt_1, $dt_3 ), 1, 'Different timezone and different date/time' ); diff --git a/t/lib/Dates.pm b/t/lib/Dates.pm index 1aa1adc233..330d5c58a1 100644 --- a/t/lib/Dates.pm +++ b/t/lib/Dates.pm @@ -24,8 +24,6 @@ sub compare { my ( $got, $expected, $description ) = @_; my $dt_got = dt_from_string($got); my $dt_expected = dt_from_string($expected); - $dt_got->set_time_zone('floating'); - $dt_expected->set_time_zone('floating'); my $diff = $dt_got->epoch - $dt_expected->epoch; if ( abs($diff) < 6 ) { return 0 } return $diff > 0 ? 1 : -1; -- 2.39.5