From 076c5bce8d772707a3b7ddec0c3b70c0b018caa2 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 13 Apr 2026 03:04:38 +0000 Subject: [PATCH] Bug 39748: Fix Koha::Patron->is_expired to calculate using floating timezone This patch updates Koha::Patron->is_expired so that it uses the floating timezone for its datemath calculation. Test plan: 0. Apply only the first patch including the unit test 1. prove -v t/db_dependent/Koha/ILL/Request.t \ t/db_dependent/Koha/Patron/Restriction.t \ t/db_dependent/Koha/Patrons.t \ t/db_dependent/Koha/AdditionalContents.t \ t/db_dependent/ILSDI_Services.t 2. Note that the unit tests fail 3. Apply the patch including the fix 4. prove -v t/db_dependent/Koha/ILL/Request.t \ t/db_dependent/Koha/Patron/Restriction.t \ t/db_dependent/Koha/Patrons.t \ t/db_dependent/Koha/AdditionalContents.t \ t/db_dependent/ILSDI_Services.t 5. Note that all unit tests pass now 6. Bonus points: - Add the following to the top of /etc/koha/sites/kohadev/plack.psgi before Modern::Perl: use Test::MockTime; BEGIN { Test::MockTime::set_absolute_time('1745580600'); } - koha-plack --restart kohadev - Look at the About page and do some circulation - Without the patches, you'll get an internal server error - With the patches, it'll just work Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Katrin Fischer Signed-off-by: Lucas Gass --- Koha/Patron.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 79db6bb9ea..aa7643cf63 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -931,7 +931,12 @@ sub is_expired { my ($self) = @_; return 0 unless $self->dateexpiry; return 0 if $self->dateexpiry =~ '^9999'; - return 1 if dt_from_string( $self->dateexpiry ) < dt_from_string->truncate( to => 'day' ); + + #NOTE: We set the timezone to floating so that we can do datetime math regardless of impossible local (DST) times + #In this case, we need a comparison with "local midnight" but local midnight doesn't exist for some timezones. + return 1 + if ( dt_from_string( $self->dateexpiry )->set_time_zone('floating') ) < + ( dt_from_string()->set_time_zone('floating')->truncate( to => 'day' ) ); return 0; }