p5-time-moment icon indicating copy to clipboard operation
p5-time-moment copied to clipboard

Inconsistent behaviour of delta_days()

Open borekl opened this issue 2 years ago • 4 comments

~$ cat t.pl
use Time::Moment;
use v5.10;

my $before = Time::Moment->from_string('20121231T235959Z');
my $after  = Time::Moment->from_string('20130101T000000Z');

say 'Years:   ', $before->delta_years($after);
say 'Months:  ', $before->delta_months($after);
say 'Days:    ', $before->delta_days($after);
say 'Hours:   ', $before->delta_hours($after);
say 'Minutes: ', $before->delta_minutes($after);

~$ perl t.pl
Years:   0
Months:  0
Days:    1
Hours:   0
Minutes: 0

Why does delta_days method behave differently from the rest of the delta_* methods? Is this intended behavior?

borekl avatar Sep 10 '22 19:09 borekl

Why do you think it’s inconsistent? The difference is one day between $before and $after. The difference in years and months is in terms of complete units as documented.

chansen avatar Jul 23 '23 09:07 chansen

This could be further clarified in the documentation with a few examples.

chansen avatar Jul 23 '23 09:07 chansen

It says 'complete days' in the documentation, exactly same formulation is used for the rest of the 'delta' methods. Do you want to tell me that between $before and $after one complete day elapsed?

borekl avatar Jul 23 '23 10:07 borekl

The difference in days between the given local dates 20121231 and 20130101 is one day. The delta_days routine considers only the local date.

chansen avatar Jul 23 '23 11:07 chansen