#!/usr/bin/perl ######################################## ##### ##### Ryan's HTML Calendar Maker ##### ##### version 1.0 ##### copyright 2001 ##### ######################################## ################################################ ####################Variables#################### # # $dayoftheweek - The start day. # 0 : Sunday # -1 : Monday # -2 : Tuesday # -3 : Wednesday # -4 : Thursday # -5 : Friday # -6 : Saturday # # $daysinmonth - Number of days in a particular # month. # # $numofweeks - Number of weeks for the # given month. # # $spacing - A number used in determining # the spacing of the entries. # Calculated. # # $monthname - The name of the given month. # # $year - The given year. # ################################################# use CGI; $query = new CGI; print $query->header( ); $chosenmonth = $query->param("month"); $year = $query->param("year"); unless ($chosenmonth >= 1 && $chosenmonth <= 12) { die "Invalid entry.\n"; } $chosenmonth--; @dates = (["January",31],["February",28],["March",31],["April",30],["May",31], ["June",30],["July",31],["August",31],["September",30],["October",31], ["November",30],["December",31]); $monthname = $dates[$chosenmonth][0]; $daysinmonth = $dates[$chosenmonth][1]; unless ($year >= 1500 && $year <= 3999) { die "Invalid entry.\n"; } ############################## # testing for a leap year ############################## if ($chosenmonth == 1) { $daysinmonth = ($year % 400 == 0) ? 29 : ($year % 100 == 0) ? 28 : ($year % 4 == 0) ? 29 : 28; } ################################################### # Calculating the start day using the Claus method ################################################### $dayoftheweek = claus(1,$chosenmonth + 1,$year); # the 1 makes it the 1st day $dayoftheweek = 0 - $dayoftheweek; # the + 1 corrects the earlier subtraction ##################################### # Calculating the number of weeks ##################################### if($dayoftheweek == -6 && ($daysinmonth == 31 || $daysinmonth == 30)) { $numofweeks = 6; } elsif($dayoftheweek == -5 && $daysinmonth == 31) { $numofweeks = 6; } elsif($dayoftheweek == 0 && $daysinmonth == 28) { $numofweeks = 4; } else { $numofweeks = 5; } ######### # Spacer ######### $spacing = 2 * (10 - $numofweeks); ######### # Opener ######### print " "; print $monthname . " " . $year; print "
 
"; print " " x 18; print "" . uc($monthname) . " " . $year . ""; print " " x 18; print "

"; ############## # The "MEAT" ############## for($weekindex = 0;$weekindex < $numofweeks;$weekindex++) { print "\n"; for($index = 0;$index < 7;$index++) { $dayoftheweek++; if($dayoftheweek > 0 && $dayoftheweek <= $daysinmonth) { print "\n"; } print "\n"; } ########### # Closing ########### print "
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
"; print "
 " x $spacing; print "
$dayoftheweek"; print "
"; } else { print "
"; } print "
"; ################################################ # The Claus method. Found at # http://www.tondering.dk/claus/calendar.html ################################################ sub claus { my ($day,$month,$yr) = @_; $a = round(14 - $month,12); $y = $yr - $a; $m = $month - 2 + (12 * $a); $d = ($day + $y + round($y,4) - round($y,100) + round($y,400) + round(31 * $m,12)) % 7; return $d; } ######################################### # This rounding eliminates the decimal ######################################### sub round { my ($top,$bot) = @_; $div = $top / $bot; $rem = $top % $bot; $round = $div - ($rem/$bot); return ($round); }