From 2164d68396ebb324185ef8dbb9a89e46aef5158a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 4 Mar 2019 18:12:56 -0300 Subject: [PATCH] Bug 22453: Make TestBuilder generates dates taking into account the timezone I have no idea why this only appears today but TestBuilder generates dates using DateTime->now, which does not take into account the timezone. It has been highlights by a failing test today on U18. Why today whereas this patch was pushed few weeks ago? Why U18 and not D9? The output of the test is: koha_1 | # Failed test 'With BorrowerLogs and TrackLastPatronActivity we should not spam the logs' koha_1 | # at t/db_dependent/Koha/Patrons.t line 1421. koha_1 | # got: '2' koha_1 | # expected: '1' koha_1 | # Looks like you failed 1 test of 4. koha_1 | koha_1 | # Failed test 'BorrowersLog tests' koha_1 | # at t/db_dependent/Koha/Patrons.t line 1422. koha_1 | # Looks like you failed 1 test of 33. koha_1 | [19:51:44] t/db_dependent/Koha/Patrons.t Actually there are 2 logs, one for the cardnumber that is expected, and on for updated_on: "updated_on" : { "after" : "2019-03-04 21:10:00", "before" : "2019-03-04 18:10:00" } Apart from the fact that we may want to remove this updated_on field from MODIFY, the before/after dates differ from 3 hours. Here it's currently 18:10 and in UTC-3 To prevent such behaviors in tests (create stuffs in the future...), we should use our Koha::DateUtils::dt_from_string method that takes care of the timezone used in other places of Koha. Test plan: prove t/db_dependent/Koha/Patrons.t May fail without this patch. --- t/lib/TestBuilder.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index be2a83491e..b0eb922581 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -7,6 +7,7 @@ use C4::Biblio; use C4::Items; use Koha::Biblios; use Koha::Items; +use Koha::DateUtils qw( dt_from_string ); use Bytes::Random::Secure; use Carp; @@ -485,12 +486,12 @@ sub _gen_real { sub _gen_date { my ($self, $params) = @_; - return $self->schema->storage->datetime_parser->format_date(DateTime->now()) + return $self->schema->storage->datetime_parser->format_date(dt_from_string) } sub _gen_datetime { my ($self, $params) = @_; - return $self->schema->storage->datetime_parser->format_datetime(DateTime->now()); + return $self->schema->storage->datetime_parser->format_datetime(dt_from_string); } sub _gen_text { -- 2.11.0