NAME HTML::CalendarMonthSimple - Perl Module for Generating HTML Calendars SYNOPSIS use HTML::CalendarMonthSimple; $cal = new HTML::CalendarMonthSimple('year'=>2001,'month'=>2); $cal->width('50%'); $cal->border(10); $cal->header('Text at the top of the Grid'); $cal->setcontent(14,"Valentine's Day"); $cal->setdatehref(14, 'http://localhost/'); $cal->addcontent(14,"
Don't forget to buy flowers."); $cal->addcontent(13,"Guess what's tomorrow?"); $cal->bgcolor('pink'); print $cal->as_HTML; DESCRIPTION HTML::CalendarMonthSimple is a Perl module for generating, manipulating, and printing a HTML calendar grid for a specified month. It is intended as a faster and easier-to-use alternative to HTML::CalendarMonth. This module requires the Date::Calc module, which is available from CPAN if you don't already have it. INTERFACE METHODS new(ARGUMENTS) Naturally, new() returns a newly constructed calendar object. Recognized arguments are 'year' and 'month', to specify which month's calendar will be used. If either is omitted, the current value is used. An important note is that the month and the year are NOT the standard C or Perl -- use a month in the range 1-12 and a real year, e.g. 2001. # Examples: # Create a calendar for this month. $cal = new HTML::CalendarMonthSimple(); # One for a specific month/year $cal = new HTML::CalendarMonthSimple('month'=>2,'year'=>2000); # One for "the current month" in 1997 $cal = new HTML::CalendarMonthSimple('year'=>1997); year() month() monthname() These methods simply return the year/month of the calendar. monthname() returns the text name of the month, e.g. "December". setcontent(DATE,STRING) addcontent(DATE,STRING) getcontent(DATE) These methods are used to control the content of date cells within the calendar grid. The DATE argument may be a numeric date or it may be a string describing a certain occurrence of a weekday, e.g. "3MONDAY" to represent "the third Monday of the month being worked with", or it may be the plural of a weekday name, e.g. "wednesdays" to represent all occurrences of the given weekday. The weekdays are case-insensitive. Since plural weekdays (e.g. 'wednesdays') is not a single date, getcontent() will return the content only for the first occurrence of that day within a month. # Examples: # The cell for the 15th of the month will now say something. $cal->setcontent(15,"An Important Event!"); # Later down the program, we want the content to be boldfaced. $cal->setcontent(15,"" . $cal->getcontent(15) . ""); # addcontent() does not clobber existing content. # Also, if you setcontent() to '', you've deleted the content. $cal->setcontent(16,''); $cal->addcontent(16,"
Hello World
"); $cal->addcontent(16,"Hello Again
"); print $cal->getcontent(16); # Prints 2 sentences # Padded and decimal numbers may be used, as well: $cal->setcontent(3.14159,'Third of the month'); $cal->addcontent('00003.0000','Still the third'); $cal->getcontent('3'); # Gets the 2 sentences # The second Sunday of May is some holiday or another... $cal->addcontent('2sunday','Some Special Day') if ($cal->month() == 5); # Every Wednesday is special... $cal->addcontent('wednesdays','Every Wednesday!'); # either of these will return the content for the 1st Friday of the month $cal->getcontent('1friday'); $cal->getcontent('Fridays'); # you really should use '1friday' for the first Friday Note: A change in 1.21 is that all content is now stored in a single set of date-indexed buckets. Previously, the content for weekdays, plural weekdays, and numeric dates were stored separately and could be fetched and set independently. This led to buggy behavior, so now a single storage set is used. # Example: # if the 9th of the month is the second Wednesday... $cal->setcontent(9,'ninth'); $cal->addcontent('2wednesday','second wednesday'); $cal->addcontent('wednesdays','every wednesday'); print $cal->getcontent(9); In version 1.20 and previous, this would print 'ninth' but in 1.21 and later, this will print all three items (since the 9th is not only the 9th but also a Wednesday and the second Wednesday). This could have implications if you use setcontent() on a set of days, since other content may be overwritten: # Example: # the second setcontent() effectively overwrites the first one $cal->setcontent(9,'ninth'); $cal->setcontent('2wednesday','second wednesday'); $cal->setcontent('wednesdays','every wednesday'); print $cal->getcontent(9); # returns 'every wednesday' because that was the last assignment! as_HTML() This method returns a string containing the HTML table for the month. # Example: print $cal->as_HTML(); It's okay to continue modifying the calendar after calling as_HTML(). My guess is that you'd want to call as_HTML() again to print the further-modified calendar, but that's your business... weekstartsonmonday([1|0]) By default, calendars are displayed with Sunday as the first day of the week (American style). Most of the world prefers for calendars to start the week on Monday. This method selects which type is used: 1 specifies that the week starts on Monday, 0 specifies that the week starts on Sunday (the default). If no value is given at all, the current value (1 or 0) is returned. # Example: $cal->weekstartsonmonday(1); # switch over to weeks starting on Monday $cal->weekstartsonmonday(0); # switch back to the default, where weeks start on Sunday # Example: print "The week starts on " . ($cal->weekstartsonmonday() ? 'Sunday' : 'Monday') . "\n"; setdatehref(DATE,URL_STRING) getdatehref(DATE) These allow the date-number in a calendar cell to become a hyperlink to the specified URL. The DATE may be either a numeric date or any of the weekday formats described in setcontent(), et al. If plural weekdays (e.g. 'wednesdays') are used with getdatehref() the URL of the first occurrence of that weekday in the month will be returned (since 'wednesdays' is not a single date). # Example: # The date number in the cell for the 15th of the month will be a link # then we change our mind and delete the link by assigning a null string $cal->setdatehref(15,"http://sourceforge.net/"); $cal->setdatehref(15,''); # Example: # the second Wednesday of the month goes to some website $cal->setdatehref('2wednesday','http://www.second-wednesday.com/'); # Example: # every Wednesday goes to a website # note that this will effectively undo the '2wednesday' assignment we just did! # if we wanted the second Wednesday to go to that special URL, we should've done that one after this! $cal->setdatehref('wednesdays','http://every-wednesday.net/'); contentfontsize([STRING]) contentfontsize() sets the font size for the contents of the cell, overriding the browser's default. Can be expressed as an absolute (1 .. 6) or relative (-3 .. +3) size. border([INTEGER]) This specifies the value of the border attribute to thecells. The effect in most web browsers is that they will be boldfaced and centered. If set to 0, the weekday headers will be in | cells and in normal text. For both functions, if no value is specified, the current value is returned. cellalignment([STRING]) vcellalignment([STRING]) cellalignment() sets the value of the align attribute to the | tag
for each day's cell. This controls how text will be horizontally
centered/aligned within the cells. vcellalignment() does the same for
vertical alignment. By default, content is aligned horizontally "left"
and vertically "top"
Any value can be used, if you think the web browser will find it
interesting. Some useful alignments are: left, right, center, top, and
bottom.
header([STRING])
By default, the current month and year are displayed at the top of the
calendar grid. This is called the "header".
The header() method allows you to set the header to whatever you like.
If no new header is specified, the current header is returned.
If the header is set to an empty string, then no header will be printed
at all. (No, you won't be stuck with a big empty cell!)
# Example:
# Set the month/year header to something snazzy.
my($y,$m) = ( $cal->year() , $cal->monthname() );
$cal->header(" |
---|