Skip Menu |

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

Report information
The Basics
Id: 116671
Status: resolved
Priority: 0/
Queue: Date-Manip

People
Owner: Nobody in particular
Requestors: goeran [...] uddeborg.se
Cc:
AdminCc:

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



CC: Andrew Ruthven <andrew [...] etc.gen.nz>
Subject: DateCalc always answers in units of hours
Date: Tue, 2 Aug 2016 22:59:47 +0200
To: bug-Date-Manip [...] rt.cpan.org
From: Göran Uddeborg <goeran [...] uddeborg.se>
While looking at the mythtv-status tool, I found what I believe to be a bug in Date-Manip. It is reproducible with the script below. When I run it, it returns 0:0:0:0:49:2:3. That is, 49 hours, rather than 0:0:0:2:1:2:3, a.k.a. two days and one hour, as I would expect. I don't know perl well at all, so there might be some subtlety here I'm missing. But the mythtv-status author (cc:ed) seems to confirm my suspicion, so I felt brave enough to venture this report. :-) I've tried with both DM5, DM6, and without the initial block completely, and all behave the same. ================ test script ================ #!/usr/bin/perl -w { no warnings 'once'; $Date::Manip::Backend = 'DM6'; } use Date::Manip; my $err; my $diff; $diff = DateCalc('2016-07-26T00:00:00', '2016-07-28T01:02:03', \$err, 0); print $diff;
CC: Andrew Ruthven <andrew [...] etc.gen.nz>
Subject: [rt.cpan.org #116671] DateCalc always answers in units of hours
Date: Tue, 2 Aug 2016 23:06:41 +0200
To: bug-Date-Manip [...] rt.cpan.org
From: Göran Uddeborg <goeran [...] uddeborg.se>
Doh, I forgot to mention the versions I use. I'm running on a Fedora 24 system with the following packages: perl-5.22.2-360.fc24.x86_64 perl-Date-Manip-6.54-1.fc24.noarch
This is actually not a bug. You are doing an exact calculation, so an exact delta is created. An exact delta is one in which ALL values have an exactly known length. Since Date::Manip ignores leap seconds, it is known that every single minute is 60 seconds, and every single hour is 60 minutes. It is NOT known how long a day is however. Due to daylight saving time, a day may be 23, 24, or 25 hours (or even other values at various times, especially at times when the gregorian calendar was first adopted). So, you get a delta with only h:m:s values (which is what you see). Now, if you use the newer object-oriented interface, you can do: my $d1 = '2016-07-26T00:00:00'; my $d2 = '2016-07-28T01:02:03'; my $diff; my $date1 = new Date::Manip::Date; $date1->parse($d1); my $date2 = $date1->new_date(); $date2->parse($d2); my $delta = $date1->calc($date2,'semi'); $diff = $delta->value(); print "$diff\n"; and you get: 0:0:0:2:1:2:3 which is what you are looking for. A semi-exact delta treats a day as always 24 hours (which works MOST but not all of the time). I never added the modes available in the newer OO version to the older functional version (i.e. DM6) because limitations in the functional interface restrict just how much of the OO functionality can be used. I'll look into it a bit and see if I can add those modes, but in the meantime, you can use the OO interface to get what you want. I'd definitely read the Date::Manip::Calc document for a lot more information about the different ways to do calculations.
For clarification, the important line is: my $delta = $date1->calc($date2,'semi'); where the type of calculation is specified as the 2nd argument (in this case 'semi' meaning semi-exact calculation.
Subject: [rt.cpan.org #116671] Resolved: DateCalc always answers in units of hours
Date: Wed, 3 Aug 2016 20:16:38 +0200
To: bug-Date-Manip [...] rt.cpan.org
From: Göran Uddeborg <goeran [...] uddeborg.se>
Ok, I see now it is clearly documented in Date::Manip::Calc man page. I was only reading the DM5 and DM6 pages, despite the reference. A bit sloppy on my part. Thanks for your explanation!