--- ConnorCalendar/calendar.pl 2013/05/28 22:07:14 1.2 +++ ConnorCalendar/calendar.pl 2013/05/28 22:58:31 1.3 @@ -8,7 +8,7 @@ | | Nicholas DeClario | March 2009 -| $Id: calendar.pl,v 1.2 2013/05/28 22:07:14 nick Exp $ +| $Id: calendar.pl,v 1.3 2013/05/28 22:58:31 nick Exp $ | +------------------------------------------------------------------------------ =end comment @@ -26,10 +26,12 @@ use Calendar::Simple; use Date::Calendar::Year qw( :all ); use Date::Calendar::Profiles qw( $Profiles ); +my $VERSION = qw/$Id: calendar.pl,v 1.3 2013/05/28 22:58:31 nick Exp $/; my $DEBUG = ""; my $URL = "http://demandred.dyndns.org/cgi-bin/ConnorCalendar/index.cgi"; my %post_in = ( ); my %opts = &fetchOptions( ); +my @list = ( ); my @months = qw/ January February March April May June July August September October Novemeber December /; my %holidays = ( @@ -48,6 +50,8 @@ my %specials = ( "11/28" => "even", "5/6" => "odd", ); +my @weekend = qw/ 2011 8 12 /; +my %weekends = &calcWeekends( @weekend ); &ReadParse( ); @@ -65,8 +69,8 @@ print "Weekends and special days I have my $year_us = Date::Calendar::Year->new( $YEAR, $Profiles->{'US-FL'} ); my @hdays = $year_us->labels( ); -$DEBUG = "Holidays for $YEAR:\n"; -foreach ( sort @hdays ) { $DEBUG .= $_ ."\n"; } +#$DEBUG = "Holidays for $YEAR:\n"; +#foreach ( sort @hdays ) { $DEBUG .= $_ ."\n"; } print "
labels( $YEAR, $month, $day ) )[1]; if( &IHaveConnor( $h_day ) ) { + push @list, $h_day; print sprintf "%2d ", $day; } elsif ( &isSpecial( $YEAR, $month, $day ) || &isWeekend( $YEAR, $month, $day ) ) { @@ -112,7 +117,12 @@ for( my $month = 1; $month <= 12; $month $row++; } print ""; -print "
$DEBUG
"; +print "
List of Special/Holidays I have Connor:
";
+print map { $_ . "\n" } sort @list;
+print "


Version: $VERSION
"; +print "CVS:
http://demandred.dyndns.org/cgi-bin/cvsweb/ConnorCalendar/"; +print "
\n\n$DEBUG
"; + ############################################################################### ############################################################################### @@ -141,8 +151,11 @@ sub isSpecial if ( defined $specials{$ref} ) { - return 1 if ( $specials{$ref} eq "all" || - $specials{$ref} eq $yr ); + if ( $specials{$ref} eq "all" || + $specials{$ref} eq $yr ) { + push @list, $ref; + return 1; + } } return 0; @@ -150,10 +163,15 @@ sub isSpecial sub isWeekend { - my $y = shift || return 0; + my $y = shift || return 0; my $m = shift || return 0; my $d = shift || return 0; + $m--; + my $ds = sprintf( "$y/$months[$m]/%02d", $d ); + + return 1 if ( defined $weekends{$ds} ); + return 0; } @@ -169,6 +187,40 @@ sub isToday return 0; } +sub calcWeekends +{ + my $y = shift; + my $m = shift; + my $d = shift; + my %weekends = ( ); + + print "Weekends I have Connor:\n"; + + use Calendar; + my $date = Calendar->new_from_Gregorian( $m, $d, $y ); + + $weekends{$date->date_string( "%Y/%M/%d" )} = 1; + &twoMore( $date ); + while ( $date->date_string( "%Y" ) <= 2026 ) + { + $date += 14; + $weekends{$date->date_string( "%Y/%M/%d" )} = 1; + &twoMore( $date ); + } + + return %weekends; + + sub twoMore + { + my $td = shift; + + $td++; + $weekends{$td->date_string( "%Y/%M/%d" )} = 1; + $td++; + $weekends{$td->date_string( "%Y/%M/%d" )} = 1; + } +} + ############################################################################### ############################################################################### sub ReadParse