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

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

Return to bug 17933