From cdfa1b0db7f98be3da503861075fecafeff9e600 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 31 Jul 2017 11:03:37 -0300 Subject: [PATCH] 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 Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart (cherry picked from commit 24b4006ecbc0a258b09500bdd8f639c7018067c0) Signed-off-by: Fridolin Somers --- 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 5a456b7164..c96764bfde 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 a5e324ff23..72bb36e9b5 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.39.5