Skip Menu |

This queue is for tickets about the Date-Calc CPAN distribution.

Report information
The Basics
Id: 16902
Status: resolved
Priority: 0/
Queue: Date-Calc

People
Owner: Nobody in particular
Requestors: david [...] landgren.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 5.4
Fixed in: (no value)



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).
From: DAVIDRW [...] cpan.org
On Wed Jan 04 05:31:25 2006, DLAND wrote: Show quoted text
> This produces: > forward delta: 1 -11 -2 -10 -58 -13 > revese delta: -1 11 2 10 58 13
That is exactly what the docs describe should happen ... ~~~~~~~~~~~~~~~~~~~~~ o "($Dy,$Dm,$Dd) = Delta_YMD($year1,$month1,$day1, $year2,$month2,$day2);" This function returns the vector ( $year2 - $year1, $month2 - $month1, $day2 - $day1 ) An error occurs if any of the two dates is invalid. ~~~~~~~~~~~~~~~~~~~~~ And right after that it describes Delta_YMDHMS() as using the same method (and nothing that adding the result back to first always yields the second). Show quoted text
> it would be nice to have this normalised 0 years, 0 months and x days.
The Delta_DHMS() function does exactly that: $ perl -MDate::Calc=:all -le '@d=Delta_DHMS(qw/2005 12 06 22 17 17/, qw/2006 1 4 11 19 4/); print "delta: @d\n"' delta: 28 13 1 47
On Mon Jan 15 15:10:57 2007, DAVIDRW wrote: Show quoted text
> On Wed Jan 04 05:31:25 2006, DLAND wrote:
> > This produces: > > forward delta: 1 -11 -2 -10 -58 -13 > > revese delta: -1 11 2 10 58 13
> > That is exactly what the docs describe should happen ... > ~~~~~~~~~~~~~~~~~~~~~ > o "($Dy,$Dm,$Dd) = Delta_YMD($year1,$month1,$day1, > $year2,$month2,$day2);" > > This function returns the vector > > ( $year2 - $year1, $month2 - $month1, $day2 - $day1 ) > > An error occurs if any of the two dates is invalid. > ~~~~~~~~~~~~~~~~~~~~~ > And right after that it describes Delta_YMDHMS() as using the same > method (and nothing that adding the result back to first always yields > the second). >
> > it would be nice to have this normalised 0 years, 0 months and x days.
> > The Delta_DHMS() function does exactly that: > $ perl -MDate::Calc=:all -le '@d=Delta_DHMS(qw/2005 12 06 22 17 17/, > qw/2006 1 4 11 19 4/); print "delta: @d\n"' > delta: 28 13 1 47
Exactly.