[Koha-bugs] [Bug 17699] DateTime durations are not correctly subtracted

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Wed Feb 22 11:21:39 CET 2017


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=17699

--- Comment #5 from Jonathan Druart <jonathan.druart at bugs.koha-community.org> ---
Just redone some tests and indeed limit seems like to be what we want:

use Modern::Perl;
use Time::Fake;

use Koha::DateUtils;
for my $date ( '2016-03-31', '2016-11-30' ) { 
    my $dt = dt_from_string( $date, 'iso' );
    Time::Fake->offset( $dt->epoch );
    say "=== $date ===";
    say dt_from_string->subtract( months => 1 )->add( months => 1 );
    say dt_from_string->subtract( months => 1, end_of_month => 'limit' )->add(
months => 1 );
    say dt_from_string->subtract( months => 1, end_of_month => 'wrap' )->add(
months => 1 );
    say dt_from_string->subtract( months => 1, end_of_month => 'wrap' )->add(
months => 1 );
}

Returns:
=== 2016-03-31 ===
2016-03-29T00:00:00
2016-03-29T00:00:00 => What we want
2016-04-02T00:00:00
2016-04-02T00:00:00
=== 2016-11-30 ===
2016-12-01T00:00:00
2016-11-30T00:00:00 => What we want
2016-11-30T00:00:00
2016-11-30T00:00:00

Wondering why 'limit' does not work as default...

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list