From beaf8076cf3a801cd680f794fee65c9e58f950df Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 17 Apr 2023 00:34:05 +0000 Subject: [PATCH] Bug 32232: Ignore DST when calculating patron age This change calculates patron age using the floating timezone, so that datetimes missing midnight don't cause fatal errors in the comparison. Test plan: 0. Apply patch 1. Change in koha-conf.xml to include Canada/Eastern 2. koha-plack --restart kohadev 3. Create a patron, setting the date of birth to one of these three dates - 1947-04-27 - 1948-04-25 - 1949-04-24 4. Save the patron 5. Patron detail page loads instead of producing fatal error Signed-off-by: Marius Mandrescu Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 5771e6f463c72e17d42478c9970df1c7fb2286f8) Signed-off-by: Matt Blenkinsop --- Koha/Patron.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 75270c71db..c7cfb941a6 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1312,8 +1312,9 @@ sub get_age { return unless $self->dateofbirth; - my $date_of_birth = dt_from_string( $self->dateofbirth ); - my $today = dt_from_string->truncate( to => 'day' ); + #Set timezone to floating to avoid any datetime math issues caused by DST + my $date_of_birth = dt_from_string( $self->dateofbirth, undef, 'floating' ); + my $today = dt_from_string(undef, undef, 'floating')->truncate( to => 'day' ); return $today->subtract_datetime( $date_of_birth )->years; } -- 2.39.5