p5-time-moment
p5-time-moment copied to clipboard
Inconsistent behaviour of delta_days()
~$ 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?
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.
This could be further clarified in the documentation with a few examples.
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?
The difference in days between the given local dates 20121231
and 20130101
is one day. The delta_days
routine considers only the local date.