From: Tim Pope Date: Mon, 21 Feb 2005 13:28:13 +0000 (+0000) Subject: Reworked holiday system. Added support for spring break X-Git-Url: http://git.tpope.net/?p=tpope-extra.git;a=commitdiff_plain;h=74b4e7b3ee855c17c8bff7ef19578d665c4bde54 Reworked holiday system. Added support for spring break --- diff --git a/perl/sctweb b/perl/sctweb index 7ca5d9f..018077c 100755 --- a/perl/sctweb +++ b/perl/sctweb @@ -10,13 +10,56 @@ use strict; use LWP::UserAgent; use HTML::TableExtract; #use Time::Local; -use Date::Calc::Object qw(Day_of_Week Decode_Day_of_Week Week_of_Year Monday_of_Week Day_of_Week_Abbreviation Delta_Days Add_Delta_Days Gmtime Mktime); +use Date::Calc::Object qw(Day_of_Week Decode_Day_of_Week Week_of_Year Monday_of_Week Day_of_Week_Abbreviation Delta_Days Add_Delta_Days Nth_Weekday_of_Month_Year Gmtime Mktime); use Date::Calendar::Profiles qw($Profiles); use Date::Calendar::Year; use vars qw($ua %opts %faculty); my ($response); +$opts{'holidays'} = { # %{$Profiles->{'US-TX'}}, + "Martin Luther King Day" => "3/Mon/Jan", + "Good Friday" => "-2", + "Spring Break Monday" => \&Spring_Break, + "Spring Break Tuesday" => \&Spring_Break, + "Spring Break Wednesday" => \&Spring_Break, + "Spring Break Thursday" => \&Spring_Break, + "Spring Break Friday" => \&Spring_Break, + "Spring Break Saturday" => \&Spring_Break, + "Fiesta Holiday" => "4/Fri/Apr", + "Memorial Day" => "5/Mon/May", + "Independence Day" => \&US_Independence, + "Labor Day" => \&US_Labor, + "Columbus Day" => "2/Mon/Oct", + "Thanksgiving Day" => "4/Thu/Nov", + "Thanksgiving Friday" => \&Thanksgiving_Friday, +}; + +sub Spring_Break { + my($year,$label) = @_; + $label =~ s/^Spring Break //; + return( Add_Delta_Days( + Nth_Weekday_of_Month_Year($year,1,1,1), + 7*(11-1) # This is for the 11th Monday of the year + +Decode_Day_of_Week($label)-1) ); +} + +sub Thanksgiving_Friday { + my($year,$label) = @_; + return( Add_Delta_Days(Nth_Weekday_of_Month_Year($year,11,4,4), 1) ); +} +sub US_Independence # Fourth of July +{ + my($year,$label) = @_; + return( &Date::Calendar::Profiles::Nearest_Workday($year,7,4) ); +} +sub US_Labor # First Monday after the first Sunday in September +{ + my($year,$label) = @_; + return( Add_Delta_Days( + Nth_Weekday_of_Month_Year($year,9,7,1), +1) ); +} + if (-r $ENV{HOME} . "/.sctwebrc") { open CONFIG, $ENV{HOME} . "/.sctwebrc"; while() { @@ -82,7 +125,7 @@ sub off_for_holidays { my $days = Delta_Days($1,$2,$3,$4,$5,$6); my $firstday = Date::Calc->new($1,$2,$3); my $lastday = Date::Calc->new($4,$5,$6); - my $year = Date::Calendar::Year->new($1, $Profiles->{'US-TX'}); + my $year = Date::Calendar::Year->new($1, $opts{'holidays'}); my @holidays=(); my @days=(); foreach(split(" ",$class{days})) { @@ -90,16 +133,12 @@ sub off_for_holidays { } foreach ($year->search("")) { my $good=1; - foreach my $x ($year->labels($_)) { - $good=0 if $x =~ /Veteran/; - $good=0 if $x =~ /Presidents/; - $good=2 if $x =~ /Thanksgiving/; - } + #foreach my $x ($year->labels($_)) { + # $good=0 if ($x =~ /Veteran/ or $x =~ /President/); + #} next unless ($year->is_full($_) && $_>=$firstday && $_<=$lastday); push @holidays, $_ - if (defined($days[Day_of_Week($_->date)]) && $good); - push @holidays, $_+1 - if (defined($days[5]) && $good==2); + if (defined($days[Day_of_Week($_->date)]) && $good > 0); } return wantarray ? @holidays : "@holidays"; }