Skip to content

Commit

Permalink
Bug 20311: Prevent get_age tests to fail on Feb 28th
Browse files Browse the repository at this point in the history
Today Feb 28th 2018:
If we subtract 18y to this DateTime object 29/02/2000 and so the patron is not major yet

use Koha::DateUtils qw( dt_from_string );
say dt_from_string('28/02/2018')->add(years => -18);
say dt_from_string('28/02/2018')->add(years => -18, end_of_month => 'limit');

will display:
2000-02-29T00:00:00
2000-02-28T00:00:00

Signed-off-by: Jonathan Druart <[email protected]>
  • Loading branch information
joubu authored and kidclamp committed Apr 6, 2018
1 parent 362c0e0 commit 72de4dd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions t/db_dependent/Koha/Patrons.t
Original file line number Diff line number Diff line change
Expand Up @@ -527,17 +527,17 @@ subtest 'get_age' => sub {

$patron->dateofbirth( undef );
is( $patron->get_age, undef, 'get_age should return undef if no dateofbirth is defined' );
$patron->dateofbirth( $today->clone->add( years => -12, months => -6, days => -1 ) );
$patron->dateofbirth( $today->clone->add( years => -12, months => -6, days => -1, end_of_month => 'limit' ) );
is( $patron->get_age, 12, 'Patron should be 12' );
$patron->dateofbirth( $today->clone->add( years => -18, months => 0, days => 1 ) );
$patron->dateofbirth( $today->clone->add( years => -18, months => 0, days => 1, end_of_month => 'limit' ) );
is( $patron->get_age, 17, 'Patron should be 17, happy birthday tomorrow!' );
$patron->dateofbirth( $today->clone->add( years => -18, months => 0, days => 0 ) );
$patron->dateofbirth( $today->clone->add( years => -18, months => 0, days => 0, end_of_month => 'limit' ) );
is( $patron->get_age, 18, 'Patron should be 18' );
$patron->dateofbirth( $today->clone->add( years => -18, months => -12, days => -31 ) );
$patron->dateofbirth( $today->clone->add( years => -18, months => -12, days => -31, end_of_month => 'limit' ) );
is( $patron->get_age, 19, 'Patron should be 19' );
$patron->dateofbirth( $today->clone->add( years => -18, months => -12, days => -30 ) );
$patron->dateofbirth( $today->clone->add( years => -18, months => -12, days => -30, end_of_month => 'limit' ) );
is( $patron->get_age, 19, 'Patron should be 19 again' );
$patron->dateofbirth( $today->clone->add( years => 0, months => -1, days => -1 ) );
$patron->dateofbirth( $today->clone->add( years => 0, months => -1, days => -1, end_of_month => 'limit' ) );
is( $patron->get_age, 0, 'Patron is a newborn child' );

$patron->delete;
Expand Down

0 comments on commit 72de4dd

Please sign in to comment.