View | Details | Raw Unified | Return to bug 30061
Collapse All | Expand All

(-)a/Koha/Patron.pm (-12 / +5 lines)
Lines 1223-1229 sub get_routing_lists { Link Here
1223
1223
1224
=head3 get_age
1224
=head3 get_age
1225
1225
1226
my $age = $patron->get_age
1226
    my $age = $patron->get_age
1227
1227
1228
Return the age of the patron
1228
Return the age of the patron
1229
1229
Lines 1231-1249 Return the age of the patron Link Here
1231
1231
1232
sub get_age {
1232
sub get_age {
1233
    my ($self)    = @_;
1233
    my ($self)    = @_;
1234
    my $today_str = dt_from_string->strftime("%Y-%m-%d");
1235
    return unless $self->dateofbirth;
1236
    my $dob_str   = dt_from_string( $self->dateofbirth )->strftime("%Y-%m-%d");
1237
1234
1238
    my ( $dob_y,   $dob_m,   $dob_d )   = split /-/, $dob_str;
1235
    return unless $self->dateofbirth;
1239
    my ( $today_y, $today_m, $today_d ) = split /-/, $today_str;
1240
1236
1241
    my $age = $today_y - $dob_y;
1237
    my $date_of_birth = dt_from_string( $self->dateofbirth );
1242
    if ( $dob_m . $dob_d > $today_m . $today_d ) {
1238
    my $today         = dt_from_string->truncate( to => 'day' );
1243
        $age--;
1244
    }
1245
1239
1246
    return $age;
1240
    return $today->subtract_datetime( $date_of_birth )->years;
1247
}
1241
}
1248
1242
1249
=head3 is_valid_age
1243
=head3 is_valid_age
1250
- 

Return to bug 30061