http://qs1969.pair.com?node_id=597370

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Date Calculation
by philcrow (Priest) on Jan 30, 2007 at 14:38 UTC
    You could try Date::Calc. From its docs:

    8) How can I add a week offset to a business date (including across year boundaries)?
    use Date::Calc qw( Business_to_Standard Add_Delta_Days Standard_to_Business ); @temp = Business_to_Standard($year,$week,$dow); @temp = Add_Delta_Days(@temp, $week_offset * 7); ($year,$week,$dow) = Standard_to_Business(@temp);

    Phil

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Date Calculation
by davorg (Chancellor) on Jan 30, 2007 at 14:40 UTC

    How do you define a business day? Is it weekdays? Or do you need to take into account public holidays and things like that?

    Here's a naive approach that just leaves you needing to define an is_business_day() subroutine which takes a time (as an epoch seconds value) as an argument.

    my $today = time; my $days_added; while (1) { $time += 24 * 60 * 60; # add a day $days_added++ if is_business_day($time); last if $days_added == 10; } print scalar localtime $time;

    Update: As ikegami correctly points out below, there's a potential bug in this program if it's run across days that don't contain 24 hours (i.e. when switching to or from daylight saving time). The fix is to normalise the time to noon (assuming that timezone changes always occur overnight). This change is left as an exercise for the reader.

      Not all days have 24 hours.
Re: Date Calculation
by davidrw (Prior) on Jan 30, 2007 at 15:19 UTC
    here's a Date::Calc solution -- assumes "business day" is just M-F, so adding 10 just needs to add in the two weekends as well, so is simply:
    use Date::Calc qw/Add_Delta_Days/; my @start = ( $year, $month, $day ); my @end = Add_Delta_Days( @start, 14 );
    If you want to take into account holidays, see the "10) How can I calculate the last business day (payday!) of a month?" example in the Date::Calc docs for reference.
Re: Date Calculation
by liverpole (Monsignor) on Jan 30, 2007 at 14:39 UTC
    Hi palette,

    Look at Date::Calc.  There is a function Add_Delta_Days which may be close to what you need.

    Additionally, there are some functions in it which deal specifically with business days:

    check_business_date Standard_to_Business Business_to_Standard

    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: Date Calculation
by Cody Pendant (Prior) on Jan 31, 2007 at 00:38 UTC
    Call me Mr States-the-obvious, but how about the module Date::Business?


    ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
    =~y~b-v~a-z~s; print
Re: Date Calculation
by gube (Parson) on Jan 30, 2007 at 15:06 UTC
    Hi,

    Updated : Sorry, Mistaken i suggest to add days i missed to read the word buisness days.

    Use DateCalc module. DateCalc