Hello,
In working with durations I have found that just getting the number of
days for a duration is not possible. I am given the impression that
in_units('days') will give me the result I'm looking for but that is not
that case. I have created a small bit of code that shows the issue I'm
having:
use strict;
use DateTime;
my $dt = DateTime->now();
foreach ( 0 ... 100 ) {
my $later = $dt->clone->add(days => $_);
my $duration = $later - $dt;
print $duration->in_units('days') . "\n";
}
The results cycle from 0 to 30 rather than simply going from 0 to 100 as I
would expect. When I look back at the docs I see confirmation of my
expectations with the following example:
$dur->in_units( 'months' ); # 27
This shows that years, which is a greater increment, is not interfering
with the results as in the case with months and days in my example. To
confirm the example in the docs all you have to do it change the two
occurrences of "days" in my example code to "months" and you will find the
results to be 0 through 100.
So are my expectations incorrect or is this a bug? If this is not a bug,
is there a way to just get the days that I'm not seeing?
Thanks,
--
David Steinbrunner