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

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

Return to bug 30061