| the complete webmaster | ||||
| tutorials | reviews | reference | ||
|
HTML CalendarThis week, I'll start a multi-week project and describe how to build a full-featured calendar control CGI in Perl. First, we'll need to decide how to represent dates for the calendar. Perl has many powerful and useful built-in functions. However, it doesn't really have many date-manipulation features beyond what's available in the standard C library. The CPAN archive undoubetly has a few useful ones. But, why not just come up with our own? The simplest method might be to use conventional the month, day and year: August 19, 1997. It could be represented internally in Perl as a string: "08/19/1997". Or, we could use three separate integer variables, $month, $day, $year. Using the object oriented extentions available in Perl5, we could create a Date class that completely encapsulates the date functions. However, because the day, month and year are stored separately, we'd need to deal with questions like these:
A much simpler approach would use a serial date format. This defines January 1st to be 1. Then, January 2nd=2,..., February 1st=32, etc. So the last day of the year (December 31st) is 365 (or 366). This way we could easily determine what the date is tomorrow (add 1 to today's date) and which day of the week it is (serial_date MOD 7). To know how many days are in this month, we'd need to consider how to convert conventional dates (Month, Day, Year) into this serial format. One method for storing serial dates is using the Julian Day Count. Julian Day 0 is January 1, 4713 BC at 12:00 GMT. For August 19, 1997, the Julian Day is 2,450,679. That means that more than 2.4 million days have passed since January 1, 4713 BC. A Modified Julian Date (MJD) is commonly used to record the date and time. This is a sequence of day numbers, with the value 0 MJD equal to 00:00 hours UTC on November 17, 1858. MJD is commonly represented by a number with five significant digits. The current version of my HTML Calendar uses the Julian Day Count. Soon, I'll convert it to use the MJD and include the ability to schedule events at a particular time. The source code for the HTML Calendar is available. It's a simple CGI program that will display a calendar and allow you to change which month is displayed.
August 1997
More next week. Author: Doug Steinwand
More articles about CGI |
| write for us | about us | advertise |
Copyright 1997, 1998 A Big Lime. All rights reserved.