[thelist] public holiday/weekend dates in Perl

Richard Bennett richard.bennett at skynet.be
Thu Jul 17 18:52:17 CDT 2003


----- Original Message -----
From: "Richard Bennett" <richard.bennett at skynet.be>
> I need to check a load of dates, to see whether they are on a (Belgian)
> public holiday, or a weekend.

A few hours later I think I have it working, so I might as well post my
solution I guess:

use Date::Calendar;
use Date::Calc::Object qw[ Day_of_Week ];
use Date::Calendar::Profiles qw($Profiles);
$cal = Date::Calendar->new( $Profiles->{'BE-NL'} ); # or wherever you're
located

sub isHolidayOrWeekend{
 if(Day_of_Week($_[0],$_[1],$_[2]) > 5){
  return 1;
 }else{
  return $cal->is_full($_[0],$_[1],$_[2]);
 };
}

if( isHolidayOrWeekend(2003,01,01) ){
    print "2003,01,01 is a day off";
}else{
    print "2003,01,01 is a working day";
}

Seems to work ok, and if the day is in a weekend, it doesn't bother to check
if it's a holiday too, to keep it as fast as possible.
Any corrections/improvements are welcome.

Richard.



More information about the thelist mailing list