Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: perl [...] 8192.net
Cc:
AdminCc:

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



Subject: Incorrect business date calculations
Date: Wed, 12 Mar 2014 13:23:40 -0700
To: bug-Date-Manip [...] rt.cpan.org
From: John <perl [...] 8192.net>
Some business date calculations are performed incorrectly. The following code should produce the same date twice, but instead produces two different dates: use Date::Manip; my $d1 = Date::Manip::Date->new( "epoch 1394651587" ); my $d2 = Date::Manip::Delta->new("54000 business seconds"); $d2->config('WorkWeekBeg', 1); $d2->config('WorkWeekEnd', 5); $d2->config('WorkDayBeg', "02:00"); $d2->config('WorkDayEnd', "17:00"); warn $d1->calc($d2)->printf('%c'); $d1 = Date::Manip::Date->new( "epoch 1394651587" ); $d2 = new Date::Manip::Delta(); $d2->config('WorkWeekBeg', 1); $d2->config('WorkWeekEnd', 5); $d2->config('WorkDayBeg', "02:00"); $d2->config('WorkDayEnd', "17:00"); $d2->set('business', [0,0,0,0,0,0,54000]); warn $d1->calc($d2)->printf('%c'); As far as I can tell the problem occurs when Date::Manip::Delta normalizes the delta.
When you create a Delta object in business mode, it uses the currently defined settings to determine the business day length. So, in your first example, you have: my $d2 = Date::Manip::Delta->new("54000 business seconds"); $d2->config('WorkWeekBeg', 1); $d2->config('WorkWeekEnd', 5); $d2->config('WorkDayBeg', "02:00"); $d2->config('WorkDayEnd', "17:00"); In this case, your $d2->config lines have no impact... the delta was determined (with the default 8:00-5:00 business day) in the first line. In your second example, you do: d2 = new Date::Manip::Delta(); $d2->config('WorkWeekBeg', 1); $d2->config('WorkWeekEnd', 5); $d2->config('WorkDayBeg', "02:00"); $d2->config('WorkDayEnd', "17:00"); $d2->set('business', [0,0,0,0,0,0,54000]); so when you set the value of the delta, your 2:00-17:00 work day is already defined and it uses those values. === As a side note, your code REALLY needs to be rewritten as: $d1 = Date::Manip::Date->new( "epoch 1394651587" ); $d2 = $d1->new_delta(); otherwise you have two different sets of config variables running around, and it will surely confuse you at some point.