Bugzilla – Attachment 131858 Details for
Bug 30061
Simplify Koha::Patron->get_age
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30061: Make Koha::Patron->get_age use DateTime math
Bug-30061-Make-KohaPatron-getage-use-DateTime-math.patch (text/plain), 1.96 KB, created by
Marcel de Rooy
on 2022-03-18 07:49:40 UTC
(
hide
)
Description:
Bug 30061: Make Koha::Patron->get_age use DateTime math
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2022-03-18 07:49:40 UTC
Size:
1.96 KB
patch
obsolete
>From f06b98c05f5d87faa65bd04f81f6aebc9bce3aa7 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 9 Feb 2022 10:45:15 -0300 >Subject: [PATCH] Bug 30061: Make Koha::Patron->get_age use DateTime math >Content-Type: text/plain; charset=utf-8 > >This patch does what the title says. Instead of converting dates to >strings and performing math manually, we can just use the DateTime >objects we have and calculate the DateTime::Duration there's between >them, to get the years count. > >To test: >1. Run: > $ kshell > k$ prove t/db_dependent/Koha/Patrons.t >=> SUCCESS: Tests pass >2. Apply this patch >3. Repeat 1 >=> SUCCESS: Tests pass >4. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: David Nind <david@davidnind.com> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/Patron.pm | 16 +++++----------- > 1 file changed, 5 insertions(+), 11 deletions(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 6414abf9cb..0c16079fa9 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -1223,7 +1223,7 @@ sub get_routing_lists { > > =head3 get_age > >-my $age = $patron->get_age >+ my $age = $patron->get_age > > Return the age of the patron > >@@ -1231,19 +1231,13 @@ Return the age of the patron > > sub get_age { > my ($self) = @_; >- my $today_str = dt_from_string->strftime("%Y-%m-%d"); >- return unless $self->dateofbirth; >- my $dob_str = dt_from_string( $self->dateofbirth )->strftime("%Y-%m-%d"); > >- my ( $dob_y, $dob_m, $dob_d ) = split /-/, $dob_str; >- my ( $today_y, $today_m, $today_d ) = split /-/, $today_str; >+ return unless $self->dateofbirth; > >- my $age = $today_y - $dob_y; >- if ( $dob_m . $dob_d > $today_m . $today_d ) { >- $age--; >- } >+ my $date_of_birth = dt_from_string( $self->dateofbirth ); >+ my $today = dt_from_string->truncate( to => 'day' ); > >- return $age; >+ return $today->subtract_datetime( $date_of_birth )->years; > } > > =head3 is_valid_age >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30061
:
130362
|
131360
| 131858