From f2c2d94e33b72978369d9a2463c8d597b6aca828 Mon Sep 17 00:00:00 2001
From: David Cook <dcook@prosentient.com.au>
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 <timezone></timezone> 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
---
 Koha/Patron.pm | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Koha/Patron.pm b/Koha/Patron.pm
index f0e1734217..2e99963d4e 100644
--- a/Koha/Patron.pm
+++ b/Koha/Patron.pm
@@ -1315,6 +1315,10 @@ sub get_age {
     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
+    $date_of_birth->set_time_zone('floating') unless $date_of_birth->time_zone->is_floating;
+    $today->set_time_zone('floating') unless $today->time_zone->is_floating;
+
     return $today->subtract_datetime( $date_of_birth )->years;
 }
 
-- 
2.30.2