Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

dates and holidays

by learn2earn (Acolyte)
on Feb 17, 2010 at 16:20 UTC ( #823749=perlquestion: print w/replies, xml ) Need Help??
learn2earn has asked for the wisdom of the Perl Monks concerning the following question:

I have a link for chat on my existing website, which I would like to hide for company holidays, I am trying to figure out the best way to go about this, so far, I have the list of holidays, an array of month names and the localtime function, I would like to setup a regex to search through the month names array and spit out whether or not the month is a holiday month, I am thinking then I could create a hash array of actual month-> holiday as elements days that are holidays and have it search through them to determine if there is a holiday that day. I am not real versed in either so suggestions are welcomed if there is a better way to go about this. Thanks

Replies are listed 'Best First'.
Re: dates and holidays
by Corion (Pope) on Feb 17, 2010 at 16:24 UTC

    My advice is to have a database table of all days for the next two years where support is unavailable and to look in that table for whether support is unavailable for today. Using any kind of calculations to determine dates will bring you no end of pain as there are lots of special cases that will come up.

Re: dates and holidays
by apl (Monsignor) on Feb 17, 2010 at 17:15 UTC
    Take a look here. The Business::Date module supports tracking holidays, though you do have to specify the list of dates once a year.
Re: dates and holidays
by cdarke (Prior) on Feb 17, 2010 at 16:41 UTC
    Keep a list of holidays days by day-of-the year, rather than month/day (you could even do it by epoc time instead). Here is some code that might help:
    use warnings; use strict; use POSIX; my $yday = (localtime())[7]; print "Today is $yday\n"; my $mday = 25; my $month = 12; my $year = 2010; my $time_t = POSIX::mktime(0, 0, 0, $mday-1, $month-1, $year-1900); my $cday = (localtime($time_t))[7]; print "Christmas day 2010 is day $cday\n";
    You can still store these day numbers as a hash key (with an undef value).
Re: dates and holidays
by Krambambuli (Curate) on Feb 18, 2010 at 15:46 UTC
    Maybe you could give Date::Manip a try.

    The following code
    #!/usr/bin/perl use strict; use warnings; use Date::Manip; Date_Init("ConfigFile=/tmp/Manip.cnf"); my $name1 = Date_IsHoliday( '2010-02-15'); print "$name1\n";
    would print

    Washington's Birthday

    "out of the box", and the holidays to remember are easily configurable for your own needs.
    Just take care to copy Manip.cnf from the test suite within the installation bundle to a convenient place.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://823749]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2018-05-24 03:26 GMT
Find Nodes?
    Voting Booth?