From e893181d2c9e644abb9ca9115a629fb63962efdc Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 27 Jan 2021 12:18:06 +0000 Subject: [PATCH] Bug 24609: Add test for timezone handling This patch adds an additional set of tests for test for how timezones are handled if we are passed an rfc3339 string with a timezone offset. Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/api/v1/checkouts.t | 35 ++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/checkouts.t b/t/db_dependent/api/v1/checkouts.t index eee996794f..835ffc70e3 100755 --- a/t/db_dependent/api/v1/checkouts.t +++ b/t/db_dependent/api/v1/checkouts.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 98; +use Test::More tests => 101; use Test::MockModule; use Test::Mojo; use t::lib::Mocks; @@ -228,11 +228,44 @@ $t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/all my $new_date_due = Koha::DateUtils::dt_from_string( $issue2->date_due ); $new_date_due->add(days => 2); $new_date_due = output_pref({ dateformat => "rfc3339", dt => $new_date_due }); +diag("The new date due should be: $new_date_due"); $t->put_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id => json => { due_date => $new_date_due }) ->status_is(200, 'Due date updated successfully') ->json_is('/due_date' => $new_date_due); +# Test for date handling for client differs from server locale +$new_date_due = $date_due->clone->set_time_zone( 'Australia/Sydney' ); +$new_date_due->add(days => 2); +my $offset_rfc3339 = $new_date_due . get_offset_string($new_date_due->offset); +my $offset_servertime = output_pref({ dateformat => "rfc3339", dt => $new_date_due }); +$t->put_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id => json => { due_date => $offset_rfc3339}) + ->status_is(200, 'Due date updated successfully') + ->json_is('/due_date' => $offset_servertime); + $t->put_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id => json => { item_id => 3 }) ->status_is(400, 'readOnly properties not updateable'); $schema->storage->txn_rollback; + +# Borrowed from 2020 release of DateTime +sub get_offset_string { + my $offset = shift; + my $sep = ':'; + + my $sign = $offset < 0 ? '-' : '+'; + + $offset = abs($offset); + + my $hours = int( $offset / 3600 ); + $offset %= 3600; + my $mins = int( $offset / 60 ); + $offset %= 60; + my $secs = int($offset); + + return ( + $secs + ? sprintf( '%s%02d%s%02d%s%02d', + $sign, $hours, $sep, $mins, $sep, $secs ) + : sprintf( '%s%02d%s%02d', $sign, $hours, $sep, $mins ) + ); +} -- 2.32.0