Subject: | Odd date deltas when the year wraps |
Consider the following program:
#! /usr/bin/perl -w
use strict;
use Date::Calc 'Delta_YMDHMS';
my @d1 = qw(2005 12 06 22 17 17);
my @d2 = qw(2006 1 4 11 19 4);
my @delta;
@delta = Delta_YMDHMS( @d1, @d2 );
print "forward delta: @delta\n";
@delta = Delta_YMDHMS( @d2, @d1 );
print "revese delta: @delta\n";
__END__
This produces:
forward delta: 1 -11 -2 -10 -58 -13
revese delta: -1 11 2 10 58 13
That is, the delta is one year, minus eleven months. I can sort of see why this is the case, but it would be nice to have this normalised 0 years, 0 months and x days.
The only work around I can think of is to add 180 days to both dates and then recalculate the delta. Or perhaps adding -11 months to both (the first field that flips its sign with respect to the previous field).