davemabe has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to get Date::Manip to calculate the number of business hours between two dates. I am seeing some peculiar results that I can't find reference to in the business mode section of the docs. When I compare "today at 1PM" with "tomorrow at 10AM" in business mode, the result is 6 hours as I was expecting. However, when I compare "today at 1PM" with "tomorrow at 1PM" in business mode, the result is 24 hours, not 9 hours as I was expecting. I am certain that ParseDate is parsing the dates correctly. It is just that DateCalc is not returning results as I expect.
Here are my effective Date::Manip configuration options relating to business mode:
WorkWeekBeg=1 WorkWeekEnd=5 WorkDayBeg=08:00 WorkDayEnd=17:00 WorkDay24Hr=0 TomorrowFirst=1

Here is the code I am using for testing:
use Date::Manip; use strict; my $mode = 2; # 2 = business mode, 1 = normal mode my $dateA = ParseDate("today at 1PM"); my $dateB = ParseDate("tomorrow at $ARGV[0]"); my $err; my $difference = Delta_Format(DateCalc($dateA,$dateB,\$err,$mode),0,"% +hh"); print "$difference hours.\n";

Running it this way: perl busihours.pl 10:00
prints out: 6 hours

while running this: perl busihours.pl 13:00
prints out: 24 hours.

Can anyone explain the behavior?

Dave

Replies are listed 'Best First'.
Re: Date::Manip business calculations
by t0mas (Priest) on Dec 12, 2000 at 19:16 UTC
    I'm no expert on this module but I guess that the delta calculated by DateCalc($dateA,$dateB,\$err,$mode) will be 1 buisness day when you feed your program 13:00.

    This is probably "misunderstod" by Delta_Format which interprets it like "He wants to know how many hours one day is" and gives you 24 hours.

    You could probably fix this by creating your own version of Delta_Format that splits the delta in its pieces (separated by colons) and make your own interpretation of what they mean (ie. 1 day = 8 hours).


    /brother t0mas