Manual Reference Pages - HTML::CALENDARMONTHSIMPLE (3)
HTML::CalendarMonthSimple - Perl Module for Generating HTML Calendars
$cal = new HTML::CalendarMonthSimple(year=>2001,month=>2);
$cal->header(Text at the top of the Grid);
$cal->addcontent(14,"<p>Dont forget to buy flowers.");
$cal->addcontent(13,"Guess whats tomorrow?");
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 dont already have it.
Naturally, new() returns a newly constructed calendar object.
The optional constructor arguments year and month can specify which months calendar will be used. If either is omitted, the current value (e.g. today) 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.
The arguments today_year, today_month, and today_date may also be specified, to specify what today is. If not specified, the system clock will be used. This is particularly useful when the todaycolor() et al methods are used, and/or if youre dealing with multiple timezones. Note that these arguments change what today is, which means that if you specify a today_year and a today_month then you are effectively specifying a year and month argument as well, though you can also specify a year and month argument and override the today behavior.
# Create a calendar for this month.
$cal = new HTML::CalendarMonthSimple();
# A calendar for a specific month/year
$cal = new HTML::CalendarMonthSimple(month=>2,year=>2000);
# Pretend that today is June 10, 2000 and display the "current" calendar
$cal = new HTML::CalendarMonthSimple(today_year=>2000,today_month=>6,today_date=>10);
These methods simply return the year/month/date of the calendar, as specified in the constructor.
monthname() returns the text name of the month, e.g. December.
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.
# 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,"<b>" . $cal->getcontent(15) . "</b>");
# addcontent() does not clobber existing content.
# Also, if you setcontent() to , youve deleted the content.
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...
# either of these will return the content for the 1st Friday of the month
$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.
# if the 9th of the month is the second Wednesday...
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:
# the second setcontent() effectively overwrites the first one
print $cal->getcontent(9); # returns every wednesday because that was the last assignment!
This method returns a string containing the HTML table for the month.
Its okay to continue modifying the calendar after calling as_HTML(). My guess is that youd want to call as_HTML() again to print the further-modified calendar, but thats your business...
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.
$cal->weekstartsonmonday(1); # switch over to weeks starting on Monday
$cal->weekstartsonmonday(0); # switch back to the default, where weeks start on Sunday
print "The week starts on " . ($cal->weekstartsonmonday() ? Sunday : Monday) . "\n";
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).
# 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
# the second Wednesday of the month goes to some website
# 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 shouldve done that one after this!
contentfontsize() sets the font size for the contents of the cell, overriding the browsers default. Can be expressed as an absolute (1 .. 6) or relative (-3 .. +3) size.
This specifies the value of the border attribute to the <TABLE> declaration for the calendar. As such, this controls the thickness of the border around the calendar table. The default value is 5.
If a value is not specified, the current value is returned. If a value is specified, the border value is changed and the new value is returned.
This sets the value of the width attribute to the <TABLE> declaration for the calendar. As such, this controls the horizintal width of the calendar.
The width value can be either an integer (e.g. 600) or a percentage string (e.g. 80%). Most web browsers take an integer to be the tables width in pixels and a percentage to be the table width relative to the screens width. The default width is 100%.
If a value is not specified, the current value is returned. If a value is specified, the border value is changed and the new value is returned.
$cal->width(600); # absolute pixel width
$cal->width("100%"); # percentage of screen size
showdatenumbers([1 or 0])
If showdatenumbers() is set to 1, then the as_HTML() method will put date labels in each cell (e.g. a 1 on the 1st, a 2 on the 2nd, etc.) If set to 0, then the date labels will not be printed. The default is 1.
If no value is specified, the current value is returned.
The date numbers are shown in boldface, normal size font. If you want to change this, consider setting showdatenumbers() to 0 and using setcontent()/addcontent() instead.
showweekdayheaders([1 or 0])
weekdayheadersbig([1 or 0])
If showweekdayheaders() is set to 1 (the default) then calendars rendered via as_HTML() will display the names of the days of the week. If set to 0, the days names will not be displayed.
If weekdayheadersbig() is set to 1 (the default) then the weekday headers will be in <th> cells. The effect in most web browsers is that they will be boldfaced and centered. If set to 0, the weekday headers will be in <td> cells and in normal text.
For both functions, if no value is specified, the current value is returned.
cellalignment() sets the value of the align attribute to the <TD> tag for each days 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.
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 wont be stuck with a big empty cell!)
# Set the month/year header to something snazzy.
my($y,$m) = ( $cal->year() , $cal->monthname() );
$cal->header("<center><font size=+2 color=red>$m $y</font></center>\n\n");
These define the colors of the cells. If a string (which should be either a HTML color-code like #000000 or a color-word like yellow) is supplied as an argument, then the color is set to that specified. Otherwise, the current value is returned. To un-set a value, try assigning the null string as a value.
The bgcolor defines the color of all cells. The weekdaycolor overrides the bgcolor for weekdays (Monday through Friday), the weekendcolor overrides the bgcolor for weekend days (Saturday and Sunday), and the todaycolor overrides the bgcolor for todays date. (Which may not mean a lot if youre looking at a calendar other than the current month.)
The weekdayheadercolor overrides the bgcolor for the weekday headers that appear at the top of the calendar if showweekdayheaders() is true, and weekendheadercolor does the same thing for the weekend headers. The headercolor overrides the bgcolor for the month/year header at the top of the calendar. The headercontentcolor(), weekdayheadercontentcolor(), and weekendheadercontentcolor() methods affect the color of the corresponding headers contents and default to the contentcolor().
The colors of the cell borders may be set: bordercolor determines the color of the calendar grids outside border, and is the default color of the inner border for individual cells. The inner bordercolor may be overridden for the various types of cells via weekdaybordercolor, weekendbordercolor, and todaybordercolor.
Finally, the color of the cells contents may be set with contentcolor, weekdaycontentcolor, weekendcontentcolor, and todaycontentcolor. The contentcolor is the default color of cell content, and the other methods override this for the appropriate days cells.
$cal->bgcolor(white); # Set the default cell bgcolor
$cal->bordercolor(green); # Set the default border color
$cal->contentcolor(black); # Set the default content color
$cal->headercolor(yellow); # Set the bgcolor of the Month+Year header
$cal->headercontentcolor(yellow); # Set the content color of the Month+Year header
$cal->weekdayheadercolor(orange); # Set the bgcolor of weekdays headers
$cal->weekendheadercontentcolor(blue); # Set the color of weekday headers contents
$cal->weekendheadercolor(pink); # Set the bgcolor of weekends headers
$cal->weekdayheadercontentcolor(blue); # Set the color of weekend headers contents
$cal->weekendcolor(palegreen); # Override weekends cell bgcolor
$cal->weekendcontentcolor(blue); # Override weekends content color
$cal->todaycolor(red); # Override todays cell bgcolor
$cal->todaycontentcolor(yellow); # Override todays content color
print $cal->as_HTML; # Print a really ugly calendar!
These methods set the cell color and the content color for the specified date, and will return the current value if STRING is not specified. These color settings will override any of the settings mentioned above, even todaycolor() and todaycontentcolor().
The date may be a numeric date or a weekday string as described in setcontent() et al. Note that if a plural weekday is used (e.g. sundays) then, since its not a single date, the value for the first occurrence of that weekday will be returned (e.g. the first Sundays color).
# Example: a red-letter day!
# Every Tuesday is a Soylent Green day...
# Note that if the 3rd was a Tuesday, this later assignment would override the previous one.
# see the docs for setcontent() et all for more information.
nowrap([1 or 0])
If set to 1, then calendar cells will have the NOWRAP attribute set, preventing their content from wrapping. If set to 0 (the default) then NOWRAP is not used and very long content may cause cells to become stretched out.
sharpborders([1 or 0])
If set to 1, this gives very crisp edges between the table cells. If set to 0 (the default) standard HTML cells are used. If neither value is specified, the current value is returned.
FYI: To accomplish the crisp border, the entire calendar table is wrapped inside a table cell.
This specifies the height in pixels of each cell in the calendar. By default, no height is defined and the web browser usually chooses a reasonable default.
If no value is given, the current value is returned.
To un-specify a height, try specifying a height of 0 or undef.
These specify which CSS class will be attributed to the calendars table and the calendars cells. By default, no classes are specified or used.
tableclass() sets the CSS class for the calendar table.
cellclass() is used for all calendar cells. weekdaycellclass(), weekendcellclass(), and todaycellclass() override the cellclass() for the corresponding types of cells. headerclass() is used for the calendars header.
datecellclass() sets the CSS class for the cell for the specified date. This setting will override any of the other cell class settings, even todaycellclass() This date must be numeric; it cannot be a string such as 2wednesday
If no value is given, the current value is returned.
To un-specify a class, try specifying an empty string, e.g. cellclass()
These functions allow the days of the week to be renamed, which is useful for displaying the weekday headers in another language.
# show the days of the week in Spanish
# show the days of the week in German
If no value is specified (or, for weekdays() if exactly 5 arguments arent given) then the current value is returned.
BUGS, TODO, CHANGES
Changes in 1.01: Added VALIGN to cells, to make alignment work with browsers better. Added showweekdayheaders(). Corrected a bug that results in the month not fitting on the grid (e.g. March 2003). Added getdatehref() and setdatehref(). Corrected a bug that causes a blank week to be printed at the beginning of some months.
Changes in 1.02: Added the color methods.
Changes in 1.03: More color methods!
Changes in 1.04: Added the which weekday capability to addcontent(), setcontent(), and getcontent()
Changes in 1.05: addcontent(), et al can now take strings such as 06 or decimals such as 3.14 and will handle them correctly.
Changes in 1.06: Changed the which weekday interface a bit; truncations such as 2Tue no longer work, and must be spelled out entirely (2Tuesday). Added plural weekdays support (e.g. wednesdays for every wednesday).
Changes in 1.07: Fixed a typo that caused an entirely empty calendar to be displayed very small.
Changes in 1.08: Re-did the bugfixes described in 1.05, handling padded and non-integer dates.
Changes in 1.09: Fixed the 2Monday, et al support; a bug was found by Dale Wellman <firstname.lastname@example.org> where the 7th, 14th, 21st, and 28th days werent properly computing which Nth weekday they were so 1Monday wouldnt work if the first Monday was the 7th of the month.
Changes in 1.10: Added the headercontentcolor(), weekendheadercontentcolor(), and weekdayheadercontentcolor() methods, and made content headers use bgcolors, etc properly.
Changes in 1.11: The modules VERSION is now properly specified, so use statements wont barf if they specify a minimum version. Added the vcellalignment() method so vertical content alignment is independent of horizontal alignment.
Changes in 1.12: Fixed lots of warnings that were generated if <B>-wB> was used, due to many values defaulting to undef/blank. Added the sharpborders(), nowrap(), cellheight(), cellclass(), and weekdayheadersbig() methods. cellclass(), the beginning of CSS support. Thanks, Bray!
Changes in 1.13: Added more CSS methods: headerclass(), weekdaycellclass(), weekndcellclass(), todaycellclass(). Added a test to the module distribution at the urging of CPAN testers.
Changes in 1.14: Added the contentfontsize() method.
Changes in 1.15: Added the datecolor(), datecontentcolor(), datebordercolor(), and datecellclass() methods, allowind cosmetic attributes to be changed on a per-date basis.
Changes in 1.16: Fixed a very stupid bug that made addcontent() and setcontent() not work. Sorry!
Changes in 1.17: Corrected <B>-wB> warnings about uninitialized values in as_HTML().
Changes in 1.18: Added methods: tableclass(), sunday(), saturday(), weekdays(). Now day names can be internationalized!
Changes in 1.19: Fixed as_HTML() such that blank/0 values can be used for various values, e.g. border size, colors, etc. Previously, values had to be non-zero or they were assumed to be undefined.
Ver 1.20 was a mistake on my part and was immediately superseded by 1.21.
Changes in 1.21: Fixed the internals of setcontent() et al (see the methods doc for details). Made getdatehref(), setdatehref(), and datecolor() et al, able to handle weekdays in addition to numeric dates.
Changes in 1.22: Added the much-desired weekstartsonmonday() method. Now weeks can start on Monday and end with the weekend, instead of the American style of starting on Sunday.
Changes in 1.23: Added today_year() et al. Today can now be overridden in the constructor.
Changes in 1.24: Minor corrections to the HTML so it passes XML validation. Thanks a bundle, Peter!
Changes in 1.25: A minor typo correction. Nothing big.
AUTHORS, CREDITS, COPYRIGHTS
This Perl module is freeware. It may be copied, derived, used, and distributed without limitation.
HTML::CalendarMonth was written and is copyrighted by Matthew P. Sisk <email@example.com> and provided inspiration for the modules interface and features. None of Matt Sisks code appears herein.
HTML::CalendarMonthSimple was written by Gregor Mosheh <firstname.lastname@example.org> Frankly, the major inspiration was the difficulty and unnecessary complexity of HTML::CalendarMonth. (Laziness is a virtue.)
This would have been extremely difficult if not for Date::Calc. Many thanks to Steffen Beyer <email@example.com> for a very fine set of date-related functions!
Dave Fuller <firstname.lastname@example.org> added the getdatehref() and setdatehref() methods, and pointed out the bugs that were corrected in 1.01.
Danny J. Sohier <email@example.com> provided many of the color functions.
Bernie Ledwick <firstname.lastname@example.org> provided base code for the today*() functions, and for the handling of cell borders.
Justin Ainsworth <email@example.com> provided the vcellalignment() concept and code.
Jessee Porter <firstname.lastname@example.org> provided fixes for 1.12 to correct those warnings.
Bray Jones <email@example.com> supplied the sharpborders(), nowrap(), cellheight(), cellclass() methods.
Bill Turner <firstname.lastname@example.org> supplied the headerclass() method and the rest of the methods added to 1.13
Bill Rhodes <email@example.com> provided the contentfontsize() method for version 1.14
Alberto Simo\k:~es <firstname.lastname@example.org> provided the tableclass() function and the saturday(), sunday(), and weekdays() functions for version 1.18. Thanks, Alberto, Ive been wanting this since the beginning!
Blair Zajac <email@example.com> provided the fixes for 1.19
Thanks to Kurt <firstname.lastname@example.org> for the bug report that made all the new stuff in 1.21 possible.
Many thanks to Stefano Rodighiero <email@example.com> for the code that made weekstartsonmonday() possible. This was a much-requested feature that will make many people happy!
Dan Boitnott <firstname.lastname@example.org> provided today_year() et al in 1.23
Peter Venables <email@example.com> provided the XML validation fixes for 1.24
Hey! <B>The above document had some coding errors, which are explained below:B>
Around line 1171:
Non-ASCII character seen before =encoding in $cal->saturday(Sa\k:'Assuming ISO8859-1
|perl v5.20.3 ||CALENDARMONTHSIMPLE (3) ||2005-02-18 |
Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.