From b33890b44ce8b054cb0ce56bde2d7aed022ada50 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 31 Jul 2017 11:03:37 -0300 Subject: [PATCH] [SIGNED-OFF] Bug 17699: Use limit as end_of_month From DateTime::Duration pod: "" For positive durations, the "end_of_month" parameter defaults to wrap. For negative durations, the default is "limit". This should match how most people "intuitively" expect datetime math to work. """" We need end_of_month => limit for positive durations as well. Signed-off-by: Owen Leonard --- Koha/Patron/Category.pm | 2 +- t/db_dependent/Koha/Patrons.t | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Koha/Patron/Category.pm b/Koha/Patron/Category.pm index 5a456b7..c96764b 100644 --- a/Koha/Patron/Category.pm +++ b/Koha/Patron/Category.pm @@ -218,7 +218,7 @@ sub get_expiry_date { if ( $self->enrolmentperiod ) { $date ||= dt_from_string; $date = dt_from_string( $date ) unless ref $date; - return $date->add( months => $self->enrolmentperiod ); + return $date->add( months => $self->enrolmentperiod, end_of_month => 'limit' ); } else { return $self->enrolmentperioddate; } diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index fc1a2bc..19aca2b 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -248,11 +248,11 @@ subtest 'renew_account' => sub { for my $date ( '2016-03-31', '2016-11-30', dt_from_string() ) { my $dt = dt_from_string( $date, 'iso' ); Time::Fake->offset( $dt->epoch ); - my $a_month_ago = $dt->clone->subtract( months => 1 )->truncate( to => 'day' ); - my $a_year_later = $dt->clone->add( months => 12 )->truncate( to => 'day' ); - my $a_year_later_minus_a_month = $dt->clone->add( months => 11 )->truncate( to => 'day' ); - my $a_month_later = $dt->clone->add( months => 1 )->truncate( to => 'day' ); - my $a_year_later_plus_a_month = $dt->clone->add( months => 13 )->truncate( to => 'day' ); + my $a_month_ago = $dt->clone->subtract( months => 1, end_of_month => 'limit' )->truncate( to => 'day' ); + my $a_year_later = $dt->clone->add( months => 12, end_of_month => 'limit' )->truncate( to => 'day' ); + my $a_year_later_minus_a_month = $dt->clone->add( months => 11, end_of_month => 'limit' )->truncate( to => 'day' ); + my $a_month_later = $dt->clone->add( months => 1 , end_of_month => 'limit' )->truncate( to => 'day' ); + my $a_year_later_plus_a_month = $dt->clone->add( months => 13, end_of_month => 'limit' )->truncate( to => 'day' ); my $patron_category = $builder->build( { source => 'Category', value => { -- 2.1.4