From 0d15c855ff8e4449e613af4264139711064fd85e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 13 Jan 2022 06:58:18 +0100 Subject: [PATCH] Bug 29718: Mock the timezone --- t/DateUtils.t | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/t/DateUtils.t b/t/DateUtils.t index 47b9e514b59..59318e70a89 100755 --- a/t/DateUtils.t +++ b/t/DateUtils.t @@ -4,7 +4,7 @@ use DateTime::TimeZone; use C4::Context; -use Test::More tests => 79; +use Test::More tests => 80; use Test::MockModule; use Test::Warn; @@ -146,9 +146,17 @@ like( $@, qr/.*does not match the date format \(rfc3339\).*/, 'dt_from_string sh subtest 'dt_from_string - iso format' => sub { plan tests => 6; + my $module_context = Test::MockModule->new('C4::Context'); + $module_context->mock( + 'tz', + sub { + return DateTime::TimeZone->new( name => 'Europe/Paris' ); + } + ); + # Dateonly my $dt_iso = dt_from_string( '2012-01-01', 'iso' ); - cmp_ok( $dt_iso->epoch(), 'eq', '1325376000', 'dt_from_string handles dateonly string' ); + cmp_ok( $dt_iso->epoch(), 'eq', '1325372400', 'dt_from_string handles dateonly string' ); eval { $dt_iso = dt_from_string( '2012-01-32', 'iso' ); @@ -157,11 +165,11 @@ subtest 'dt_from_string - iso format' => sub { # Datetime $dt_iso = dt_from_string( '2012-01-01T23:59:59', 'iso' ); - cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with no offset assumes "local"' ); + cmp_ok( $dt_iso->epoch(), 'eq', '1325458799', 'dt_from_string with no offset assumes "local"' ); # Datetime with timezone $dt_iso = dt_from_string( '2012-01-01T23:59:59Z', 'iso' ); - cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with UTC prescribed as Z' ); + cmp_ok( $dt_iso->epoch(), 'eq', '1325462399', 'dt_from_string with UTC prescribed as Z' ); $dt_iso = dt_from_string( '2012-01-01T23:59:59+02:00', 'iso' ); cmp_ok( $dt_iso->epoch(), 'eq', '1325455199', 'dt_from_string with offset' ); -- 2.25.1