Bug 17699: Use limit as end_of_month
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 31 Jul 2017 14:03:37 +0000 (11:03 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 8 Aug 2017 12:22:09 +0000 (09:22 -0300)
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>
Koha/Patron/Category.pm
t/db_dependent/Koha/Patrons.t

index 5a456b7..c96764b 100644 (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;
     }
index fc1a2bc..19aca2b 100644 (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  => {