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

In reply to Date::Manip business calculations by davemabe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.