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

Signed-off-by: Marius Mandrescu <marius.mandrescu@inLibro.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 5771e6f463)
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
(cherry picked from commit beaf8076cf)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
David Cook 2023-04-17 00:34:05 +00:00 committed by Lucas Gass
parent 06bf531b3d
commit 0b3bc2399d
1 changed files with 3 additions and 2 deletions

View File

@ -1265,8 +1265,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;
}