The attached text file is an example of a calendar I've used for CGI purposes (I should point out this is not entirely my script, it's modified by me but the original was by a friend of mine.)
> -----Original Message----- > From: Mandar Rahurkar [mailto:[EMAIL PROTECTED] > Sent: 15 June 2004 23:22 > Cc: [EMAIL PROTECTED] > Subject: Time > > Hello All, > I was wondering if there any module in perl which will let me > add dates taking care of all the complications (i.e.,) if day is greater > than 30 change month and so on. > > Thanks, > Mandar > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response>
#! C:\web\perl\bin\perl.exe require("../admin/mkttl.conf"); use CGI; use Time::Local; ## from DMYHMS to epoch $q = new CGI; (my $true_sec, my $true_min, my $true_hour, my $true_mday, my $true_mon, my $true_year, my $true_wday, my $true_yday, my $true_isdst) = localtime(time); $days_in_month[0] = 31; $days_in_month[1] = 28; $days_in_month[2] = 31; $days_in_month[3] = 30; $days_in_month[4] = 31; $days_in_month[5] = 30; $days_in_month[6] = 31; $days_in_month[7] = 31; $days_in_month[8] = 30; $days_in_month[9] = 31; $days_in_month[10] = 30; $days_in_month[11] = 31; $months[0] = 'January'; $months[1] = 'February'; $months[2] = 'March'; $months[3] = 'April'; $months[4] = 'May'; $months[5] = 'June'; $months[6] = 'July'; $months[7] = 'August'; $months[8] = 'September'; $months[9] = 'October'; $months[10] = 'November'; $months[11] = 'December'; $days[0] = 'Sunday'; $days[1] = 'Monday'; $days[2] = 'Tuesday'; $days[3] = 'Wednesday'; $days[4] = 'Thursday'; $days[5] = 'Friday'; $days[6] = 'Saturday'; # The calendar $mon = ($q->param("month") - 1); $year = ($q->param("year")) if ($q->param("year")); $year = $true_year if ($year eq ""); # Use today's date if none are specified $mon = $true_mon if ($mon == -1); $todays_day_of_month = $true_mday if ($true_mon eq $mon && $true_year eq $year); my $first_day_of_month_epoch = timelocal(1, 0, 0,1, $mon, $year); (my $sec, my $min, my $hour, my $mday, my $mon, my $year, my $wday, my $yday, my $isdst) = localtime($first_day_of_month_epoch); $inset_month = $wday - 1; $inset_month = 6 if ($inset_month < 0); print "<table border='0' cellspacing='1' cellpadding='1' class='calendar' align='right'> <tr> <td colspan='7' align='center' class='cal_head'> <table border='0' width='100%' cellpadding='0' cellspacing='0' class='month_header'><tr><td width='10' align='left'><b><a class='bold' href='"; ## define previous and next months and years $prev_month = $mon; $prev_year = $year; if ($prev_month eq 0) { $prev_month = 12; $prev_year--; } $next_month = ($mon+2); $next_year = $year; if ($next_month eq 13) { $next_month = 1; $next_year++; } print "main.cgi?month=".$prev_month."&year=".$prev_year."'>«</a></b></td><td width='*' align='center'><a class='bold' href='main.cgi'>".$months[$mon]." ".($year + 1900)."</a></td><td width='10' align='right'><b><a class='bold' href='main.cgi?month=".$next_month."&year=".$next_year."'>»</a></b></td></tr></table> </td> </tr> <tr> <td class='day_of_week'>M</td> <td class='day_of_week'>T</td> <td class='day_of_week'>W</td> <td class='day_of_week'>T</td> <td class='day_of_week'>F</td> <td class='day_of_week'>S</td> <td class='day_of_week'>S</td> </tr>\n"; $day_position_counter = 0; $day_number_counter = 1; $final_day_number = $days_in_month[$mon]; ## first create inset $i = 0; while ($i < $inset_month){ print " <tr>\n" if $day_position_counter == 0; print " <td> </td>\n"; $day_position_counter++; $i++; } ## now create main section while ($day_number_counter <= $final_day_number){ ## setup todays info $todays_epoch_date = timelocal(0, 0, 12, ($day_number_counter), $mon, $year); print " <tr>\n" if $day_position_counter == 0; if ($todays_day_of_month eq $day_number_counter){ print " <td class='today'>".$day_number_counter."</td>\n"; } else { print " <td>".$day_number_counter."</td>\n"; } $day_position_counter++; if ($day_position_counter == 7){ $day_position_counter = 0; print " </tr>\n"; } $day_number_counter++; } ## now finish off the row if necessary while ($day_position_counter){ print " <td class='blank_date'> </td>\n"; $day_position_counter++; if ($day_position_counter == 7){ $day_position_counter = 0; print " </tr>\n"; } } print "</table>\n\n"; print "</body>\n\n"; print "</html>\n"; exit;
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>