Date::Manip hours elapsed not business hours elapsed

Discussion in 'Perl Misc' started by rutherf, Oct 27, 2006.

  1. rutherf

    rutherf Guest

    Hello
    Why does this print 49Hs and not 17Hrs as *I* expected???
    Ive tryed bus mode 2 and 3 in DateCalc and other things but it always
    gives me elapsed hrs not elapsed bus hrs
    any help appreciated!


    ==========================================
    use Date::Manip;

    Date_Init("TZ=GMT","WorkWeekBeg=1","WorkWeekEnd=5","WorkDay24Hr=0","WorkDayBeg=09:00","WorkDayEnd=17:00");
    $start = 'Oct 03 2006 09:34:28';
    $end = 'Oct 05 2006 10:34:28';

    $date1=ParseDate($start);
    $date2=ParseDate($end);

    $delta=DateCalc($date1,$date2,,2);
    $bus_hrs=Delta_Format($delta,2,,"%ht");

    print $bus_hrs;
    ====================================================
    rutherf, Oct 27, 2006
    #1
    1. Advertising

  2. rutherf

    Bob Walton Guest

    rutherf wrote:
    > Hello
    > Why does this print 49Hs and not 17Hrs as *I* expected???
    > Ive tryed bus mode 2 and 3 in DateCalc and other things but it always
    > gives me elapsed hrs not elapsed bus hrs
    > any help appreciated!
    >
    >
    > ==========================================
    > use Date::Manip;
    >
    > Date_Init("TZ=GMT","WorkWeekBeg=1","WorkWeekEnd=5","WorkDay24Hr=0","WorkDayBeg=09:00","WorkDayEnd=17:00");
    > $start = 'Oct 03 2006 09:34:28';
    > $end = 'Oct 05 2006 10:34:28';
    >
    > $date1=ParseDate($start);
    > $date2=ParseDate($end);
    >
    > $delta=DateCalc($date1,$date2,,2);
    > $bus_hrs=Delta_Format($delta,2,,"%ht");
    >
    > print $bus_hrs;
    > ====================================================
    >

    I think the confusion is in assuming that the second argument ($mode) to
    Delta_Format is the same as the fourth argument (also described as
    $mode) to DateCalc. This is not the case -- for Delta_Format, the
    second argument is either "exact" or "approx", as is hinted at in the
    documentation and may be seen by examining the Date::Manip source code.
    If you print out $delta directly, you will see that DateCalc computed
    2 days and 1 hour, which would be correct for "business mode" with the
    parameters you supplied. Delta_Format, however, knows nothing about
    "business mode", and assumes the two days are 48 hours.
    --
    Bob Walton
    Email: http://bwalton.com/cgi-bin/emailbob.pl
    Bob Walton, Oct 28, 2006
    #2
    1. Advertising

  3. rutherf

    rutherf Guest

    DOH...Thanks that makes sence!

    Bob Walton wrote:
    > rutherf wrote:
    > > Hello
    > > Why does this print 49Hs and not 17Hrs as *I* expected???
    > > Ive tryed bus mode 2 and 3 in DateCalc and other things but it always
    > > gives me elapsed hrs not elapsed bus hrs
    > > any help appreciated!
    > >
    > >
    > > ==========================================
    > > use Date::Manip;
    > >
    > > Date_Init("TZ=GMT","WorkWeekBeg=1","WorkWeekEnd=5","WorkDay24Hr=0","WorkDayBeg=09:00","WorkDayEnd=17:00");
    > > $start = 'Oct 03 2006 09:34:28';
    > > $end = 'Oct 05 2006 10:34:28';
    > >
    > > $date1=ParseDate($start);
    > > $date2=ParseDate($end);
    > >
    > > $delta=DateCalc($date1,$date2,,2);
    > > $bus_hrs=Delta_Format($delta,2,,"%ht");
    > >
    > > print $bus_hrs;
    > > ====================================================
    > >

    > I think the confusion is in assuming that the second argument ($mode) to
    > Delta_Format is the same as the fourth argument (also described as
    > $mode) to DateCalc. This is not the case -- for Delta_Format, the
    > second argument is either "exact" or "approx", as is hinted at in the
    > documentation and may be seen by examining the Date::Manip source code.
    > If you print out $delta directly, you will see that DateCalc computed
    > 2 days and 1 hour, which would be correct for "business mode" with the
    > parameters you supplied. Delta_Format, however, knows nothing about
    > "business mode", and assumes the two days are 48 hours.
    > --
    > Bob Walton
    > Email: http://bwalton.com/cgi-bin/emailbob.pl
    rutherf, Oct 28, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. blupp
    Replies:
    0
    Views:
    1,000
    blupp
    Jan 15, 2004
  2. marcie
    Replies:
    0
    Views:
    580
    marcie
    Apr 28, 2004
  3. Louis Erickson
    Replies:
    2
    Views:
    196
    James Willmore
    Sep 3, 2003
  4. Arndt, Tobias

    ParseRecur from Date::Manip

    Arndt, Tobias, Nov 14, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    382
    Jacob Heider
    Nov 15, 2003
  5. Sandman

    Date::Manip using system libraries?

    Sandman, Feb 18, 2004, in forum: Perl Misc
    Replies:
    6
    Views:
    154
    gnari
    Feb 24, 2004
Loading...

Share This Page