I want to generate html calendars

I actually have code that does this, which I use to generate study calendars for a quiz team I coach. Hmmm..., come to think of it, I also have code elsewhere that generates HTML calendars for other purposes. It's not hard.

with the ability to customize the appearance.

Customize the appearance using CSS.

Is HTML::CalendarMonth my best option

I don't know. I always just use DateTime myself. It's not like generating a calendar is hard...

update: factored out the file operations and the rest of the HTML page, so that the subroutine just returns a calendar.
sub html_calendar { my ($month, $year, $eventshashref) = @_; my $dt = DateTime->new(year => $year, month => $month, day => 1, ); my $calendar = qq[ <table class="calendarmonth"><thead> <tr><th colspan="7" class="monthname">] . $dt->month_name . qq[ $yea +r</th></tr> <tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th> +Fri</th><th>Sat</th></tr> </thead><tbody> <tr>]; $calendar .= '<td class="othermonth">&nbsp;</td>' for 1 .. ($dt->dow + % 7); while ($dt->month == $month) { $calendar .= qq[<td><span class="daynum">] . $dt->mday . '</span>' +; if (ref $eventshashref and exists $$eventshashref{$dt->mday}) { my $class = $$eventshashref{$dt->mday()}{class}; my $time = $$eventshashref{$dt->mday()}{time}; my $desc = $$eventshashref{$dt->mday()}{shortdesc}; my $tooltip = $$eventshashref{$dt->mday()}{longdesc}; $calendar .= qq[<div class="calendarevent $class"><span class="e +venttime">$time</span> <abbr title="$tooltip">$desc</abbr></div>]; } $calendar .= qq[</td>]; $dt = $dt->add(days => 1); if ($dt->dow == 7) { $calendar .= "</tr>\n <tr>", } } $calendar .= qq[</tr>\n</tbody></table>]; return $calendar; }

Call it thusly:

my $cal = html_calendar(11, 2006, { 23 => {class => 'holiday', time => '', shortdesc => 'Thanksgiving', longdesc => 'Stay home and stuff yourself.'}});

HTH.HAND.


Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. You can just call me "Mister Sanity". Why, I've got so much sanity it's driving me crazy.

In reply to Re: Looking for easy way to generate html calendars by jonadab
in thread Looking for easy way to generate html calendars by twotone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.