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

(-)a/Koha/Patron.pm (-2 / +2 lines)
Lines 545-552 Return the age of the patron Link Here
545
sub get_age {
545
sub get_age {
546
    my ($self)    = @_;
546
    my ($self)    = @_;
547
    my $today_str = dt_from_string->strftime("%Y-%m-%d");
547
    my $today_str = dt_from_string->strftime("%Y-%m-%d");
548
    my $dob_str   = dt_from_string( $self->dateofbirth ) || return;
548
    return unless $self->dateofbirth;
549
    $dob_str      = $dob_str->strftime("%Y-%m-%d");
549
    my $dob_str   = dt_from_string( $self->dateofbirth )->strftime("%Y-%m-%d");
550
550
551
    my ( $dob_y,   $dob_m,   $dob_d )   = split /-/, $dob_str;
551
    my ( $dob_y,   $dob_m,   $dob_d )   = split /-/, $dob_str;
552
    my ( $today_y, $today_m, $today_d ) = split /-/, $today_str;
552
    my ( $today_y, $today_m, $today_d ) = split /-/, $today_str;
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +3 lines)
Lines 492-504 subtest 'checkouts + get_overdues' => sub { Link Here
492
};
492
};
493
493
494
subtest 'get_age' => sub {
494
subtest 'get_age' => sub {
495
    plan tests => 6;
495
    plan tests => 7;
496
496
497
    my $patron = $builder->build( { source => 'Borrower' } );
497
    my $patron = $builder->build( { source => 'Borrower' } );
498
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
498
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
499
499
500
    my $today = dt_from_string;
500
    my $today = dt_from_string;
501
501
502
    $patron->dateofbirth( undef );
503
    is( $patron->get_age, undef, 'get_age should return undef if no dateofbirth is defined' );
502
    $patron->dateofbirth( $today->clone->add( years => -12, months => -6, days => -1 ) );
504
    $patron->dateofbirth( $today->clone->add( years => -12, months => -6, days => -1 ) );
503
    is( $patron->get_age, 12, 'Patron should be 12' );
505
    is( $patron->get_age, 12, 'Patron should be 12' );
504
    $patron->dateofbirth( $today->clone->add( years => -18, months => 0, days => 1 ) );
506
    $patron->dateofbirth( $today->clone->add( years => -18, months => 0, days => 1 ) );
505
- 

Return to bug 17933