jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:

Using CalendarMonth to generate monthly calendars leaves the page looking somewhat higgledy piggledy as the height of each calendar varies according to whether the dates are across 5 or 6 weeks, as shown:
         
January2000
Su M Tu W Th F Sa
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
         
January200X
Su M Tu W Th F Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31          

I have been trying to discover how I can persuade the module to consistently throw the larger of the calendars regardless of the days of the week, to obtain a consistent look to the page.

I looked at using last_row(); but this brings up an error "Can't find subroutine at...". I wondered if anyone had had experience of this or could shed light in some way.

  • Comment on HTML::CalendarMonth - printing a consistent (6) rows for days of the week
  • Download Code

Replies are listed 'Best First'.
Re: HTML::CalendarMonth - printing a consistent (6) rows for days of the week
by mojotoad (Monsignor) on Dec 11, 2003 at 23:55 UTC
    Give this a whirl:
    my $c = HTML::CalendarMonth->new( year => 2003, month => 1, bgcolor => 'white', ); $c->maxrow($c->maxrow + 1); print $c->as_HTML;
    This produces the calendar on the right below:

    January2000
    SuMTuWThFSa
                1
    2345678
    9101112131415
    16171819202122
    23242526272829
    3031         
    January2003
    SuMTuWThFSa
          1234
    567891011
    12131415161718
    19202122232425
    262728293031 
                 

    You can compare $c->maxrow (or $c->last_row) for each calendar in question to decide whether to add the extra row or not. Note that once you add the extra row, $c->maxrow() and $c->last_row() will yield different results -- the former pertains to the HTML table, the latter pertains to the calendar data itself.

    Cheers,
    Matt

      My humble thanks, Oh Great One, I have been able to create the following lines to compare each calendar:
      my $result = $c->last_row; unless ($result == 7) { $c->maxrow($c->maxrow + 1); }
      I don't know if a proper programmer would have done it differently, but this works for me, and I am grateful for your help.
Re: HTML::CalendarMonth - printing a consistent (6) rows for days of the week
by jmanning2k (Pilgrim) on Dec 11, 2003 at 15:35 UTC

    Why don't you try posting a code snippet - especially the one that gives you an error.

    I'd rather experiment with existing code than to redo what you've already done.

      The code I am practising with is the following:
      #!/usr/bin/perl -w use CGI qw(:standard); use Date::Calc qw(:all); use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use HTML::AsSubs; use HTML::Element; use HTML::CalendarMonth; $c = new HTML::CalendarMonth ( month => 2, year => 2003, bgcolor => 'white', ); $c->extent($c->maxrow + 2, $c->maxcol +2); $c->all->attr(bgcolor => 'cyan'); $c->item($c->month)->wrap_content(font({size => '+2'})); $c->item($c->year)->wrap_content(strong()); $c->cell(0,2)->attr(rowspan => 2); $c->cell(0,2)->attr(colspan => 7); $c->cell(0,2)->push_content(em(font({ size => +2 }, 'The calendar is part', br(),'of this table'))); print $c->as_HTML;
      If I insert   last_row(); after the print, for example I get the error: Undefined subroutine &main::last_row called at ./calMonth1.pl line 33.

      The reason I am looking at last_row is that then I might be able to define some parameters using a conditional statement.

      If you perceive that I am guessing you wouldn't be far wrong... :)

        Looks like the last_row() call should be $c->last_row().

        (Also, I think the calendars wouldn't look higgledy piggledy if they were aligned at the top -- try putting a valign=top in the tr that contains them...)