#!/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. # ################################################# print " Which month do you want to print? (1-12) >> "; $chosenmonth = ; chomp($chosenmonth); 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]; print "year? (1500-3999) >> "; $year = ; chomp($year); 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); $toOpen = lc($monthname) . $year . ".html"; open(INF,">$toOpen"); ######### # Opener ######### print INF " "; print INF $monthname . " " . $year; print INF "
 
"; print INF " " x 18; print INF "" . uc($monthname) . " " . $year . ""; print INF " " x 18; print INF "

"; ############## # The "MEAT" ############## for($weekindex = 0;$weekindex < $numofweeks;$weekindex++) { print INF "\n"; for($index = 0;$index < 7;$index++) { $dayoftheweek++; if($dayoftheweek > 0 && $dayoftheweek <= $daysinmonth) { print INF "\n"; } print INF "\n"; } ########### # Closing ########### print INF "
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
"; print INF "
 " x $spacing; print INF "
$dayoftheweek"; print INF "
"; } else { print INF "
"; } print INF "
"; close(INF); print "Done\n"; ################################################ # 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); }