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

How wouldja get the date $x days ago not counting weekends and holidays?
use POSIX; use Date::Manip; my $x=20; my $d=Date_PrevWorkDay(strftime("%Y-%m-%d", localtime), $x);
That neatly solves the weekend portion of the problem. Is there any way at all to skip holidays?

Replies are listed 'Best First'.
(jcwren) RE: Business
by jcwren (Prior) on Nov 06, 2000 at 18:54 UTC
    Define a holiday. US? European? Japanese? Religious? This is a *very* ambiguous term.

    In the US, there are banking holidays, where only banks and government offices are closed (lazy buggers!), then "official" holidays, like Christmas (unless you're Jewish), and New Years.

    --Chris

    e-mail jcwren
      Oh, it gets better. In the US in the finance industry there are days that are holidays for specific markets. So you need to separate out things like the stock and bond markets since they sometimes differ.

      And just when you thought it was under control, consider what you do if the holiday falls on the weekend. Do you take it Monday or Friday? There is no consistent rule and so correcting holidays is a periodic maintainance headache that everyone has to do every so often...

        Then there are state-specific holidays: In Utah, most people get July 24th off. And even city-specific holidays: In Santa Barbara, many get Fiesta Day off.

                - tye (but my friends call me "Tye")
RE: Business
by little (Curate) on Nov 06, 2000 at 20:05 UTC
    As jcwren pointed out there are many different days that count as holidays. Just as you like it.
    So I'd tend to use a hash to store the holidays though you can even support different countries or taste :-)
    e.g.
    holiday = (de => (common =>( xmas =>[25.12.,26.12.,27.12], newyear =>[01.01.]), saxony =>( summer =>[dd.mm.,dd.mm.], autumn =>[dd.mm.,dd.mm.]), bavaria =>( summer =>[dd.mm.,dd.mm.], autumn =>[dd.mm.,dd.mm.]) ), us =>(common =>( xmas =>[25.12.,26.12.27.12], newyear =>[01.01.]), ....), ....) );
    Well you could use any structure as you like, but I don't know any formula to just generate all those holidays as they especially in germany rotate (school holidays to ensure everybody gets once in a while the nice season and to support tourism indusry), he he
    So all I say herewith just do it in the common way as calendars and time schedulers due, simply note the holidays for each region separately and display them on demand.

    Have a nice day
    All decision is left to your taste
    Update
    little seems to be in need of getting familar with tose modules. (thanx to $code or die).
Re: Business
by cianoz (Friar) on Nov 06, 2000 at 18:53 UTC
    the Date::Manip documentation says Date_PrevWorkDay skips also holidays...
      Actually, it doesn't support holidays as standard. The documentation says:

      If $mode is 2, a business mode is used. That is, the calculation is done using business days, ignoring holidays, weekends, etc. In order to correctly use this mode, a config file must exist which contains the section defining holidays. The config file can also define the work week and the hours of the work day, so it is possible to have different config files for different businesses.
(jptxs) Re: Business
by jptxs (Curate) on Nov 06, 2000 at 23:00 UTC

    you can also use Date::Business. It's peachy keen : ) I use it for every business date related calculation in the scheduling system I'm building right now. It works so well I had to look it up in the appointment method to remember what the name was - i'd forgotten.

    "sometimes when you make a request for the head you don't
    want the big, fat body...don't you go snickering."
                                             -- Nathan Torkington UoP2K a.k.a gnat