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 <oleonard@myacpl.org>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit 24b4006ecb)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Jonathan Druart 2017-07-31 11:03:37 -03:00 committed by Fridolin Somers
parent 1416b65e09
commit cdfa1b0db7
2 changed files with 6 additions and 6 deletions

View File

@ -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;
}

View File

@ -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 => {