Some simple HTML::CalendarMonth examples


use HTML::AsSubs;
use HTML::Element;
use HTML::CalendarMonth;
$c = new HTML::CalendarMonth;
print $c->as_HTML;

Basic calendar, defaults to current month and year, white background.

         
January2000
SuMTuWThFSa
            1
2345678
9101112131415
16171819202122
23242526272829
3031         

$c->item($c->month)->wrap_content(font({size => '+2'}));
$c->item($c->dayheaders)->wrap_content(font({size => '-1'}));
$c->item(15,16,17)->wrap_content(font({size => 4, color => 'red'}));
$c->item(6,28)->wrap_content(new HTML::Element 'blink');
$c->item_daycol('Su','Sa')->attr(bgcolor => 'cyan');
print $c->as_HTML;

Slightly customized version.
HTML::CalendarMonth is obviously not subject to an 'aesthetics' pragma.

         
January2000
SuMTuWThFSa
            1
2345678
9101112131415
16171819202122
23242526272829
3031         

# Calendars are configured with 'special attributes' in addition
# to attributes you might want to pass along to HTML::ElementTable.
# The extent of the table can go beyond the cells that the calendar
# object concerns itself with, yielding 'embedded' calendars.

$c = new HTML::CalendarMonth (
			 month      => 8,
			 year       => 1969,
			 col_offset => 2,
			 row_offset => 2,
			 bgcolor    => 'wheat',
			);
$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;

Custom initialized calendar, embedded in HTML::ElementTable

                                   
    The calendar is part
of this table
   
       
    August1969   
    SuMTuWThFSa   
              12   
    3456789   
    10111213141516   
    17181920212223   
    24252627282930   
    31               
                     
                     

# Calendars can also use 'special attributes' to affect which
# headers appear in the HTML output. In these examples, a table
# is also created to contain the calendars.

@cals = (
	 new HTML::CalendarMonth,
         new HTML::CalendarMonth ( year_span => 3 ),
         new HTML::CalendarMonth ( head_y    => 0 ),
         new HTML::CalendarMonth ( head_dow  => 0 ),
         new HTML::CalendarMonth ( head_y    => 0,
                                   head_m    => 0,
                                   head_dow  => 0 ),
        );
# Center month when year is gone
$cals[2]->item($cals[2]->month)->attr(align => 'middle');
# Embolden headers
foreach (@cals) {
   $_->item($_->month,$_->year)->wrap_content(font({size => '+2'}));
   $_->item($_->dayheaders)->wrap_content(font({size => '-1'}));
}

# Generate container table
$t = new HTML::ElementTable ( maxrow => 1, maxcol => 4 );
$t->row(0)->attr(valign => 'bottom');
$t->row(1)->attr(align  => 'middle');
$t->cell(1,0)->push_content(em("Normal"));
$t->cell(1,1)->push_content(em("Year expanded"));
$t->cell(1,2)->push_content(em("Year disabled"));
$t->cell(1,3)->push_content(em("DOW disabled"));
$t->cell(1,4)->push_content(em("All headers disabled"));
# Populate container table
foreach (0..$#cals) {
   $t->cell(0,$_)->push_content($cals[$_]);
}
print $t->as_HTML;

Five calendars with different header configurations.

         
January2000
SuMTuWThFSa
            1
2345678
9101112131415
16171819202122
23242526272829
3031         
         
January2000
SuMTuWThFSa
            1
2345678
9101112131415
16171819202122
23242526272829
3031         
         
January
SuMTuWThFSa
            1
2345678
9101112131415
16171819202122
23242526272829
3031         
         
January2000
            1
2345678
9101112131415
16171819202122
23242526272829
3031         
            1
2345678
9101112131415
16171819202122
23242526272829
3031         
NormalYear expandedYear disabledDOW disabledAll headers disabled

# Calendar weeks do not have to start on Sunday.  Arbitrary days
# may be specified as the first day of the week.  For coding
# purposes, 1..7 correspond to Sun..Sat.  Week of the year
# numbers may be added as well, along with arbitrary aliasing
# of any calendar elements.

# Translations to German
%translation = (
                # Month names
                January   => 'Januar',
                February  => 'Februar',
                March     => 'März',
                April     => 'April',
                May       => 'Mai',
                June      => 'Juni',
                July      => 'Juli',
                August    => 'August',
                September => 'September',
                October   => 'Oktober',
                November  => 'November',
                December  => 'Dezember',
                # Day abreviations.
                # (are these correct?)
                Su => 'So', # Sunday    => Sonntag
                M  => 'Mo', # Monday    => Montag
                Tu => 'Di', # Tuesday   => Dienstag
                W  => 'Mi', # Wednesday => Mittwoch
                Th => 'Do', # Thursday  => Donnerstag
                F  => 'Fr', # Friday    => Freitag
                Sa => 'Sa', # Saturday  => Samstag
               );

@cals = (
	 new HTML::CalendarMonth ( month => 3),
         new HTML::CalendarMonth ( month => 3, week_begin => 2 ),
         new HTML::CalendarMonth ( month      => 3,
                                   week_begin => 2,
				   head_week  => 1 ),
         new HTML::CalendarMonth ( month      => 3,
                                   week_begin => 2,
				   head_week  => 1,
				   alias      => \%translation,
				 ),
        );
# Embolden headers
foreach (@cals) {
   $_->item($_->month,$_->year)->wrap_content(font({size => '+2'}));
   $_->item($_->dayheaders)->wrap_content(font({size => '-1'}));
}
# Illustrate week number headers
foreach (@cals[2,3]) {
  $_->item_week_nums->wrap_content(font({'size' => '-1'}));
  $_->item_week_nums->attr('bgcolor' => 'cyan');  
}

# Generate container table
$t = new HTML::ElementTable ( maxrow => 1, maxcol => 3 );
$t->row(0)->attr(valign => 'bottom');
$t->row(1)->attr(align  => 'middle');
$t->cell(1,0)->push_content(em("Default"));
$t->cell(1,1)->push_content(em("Monday 1st", br, "Day Of Week"));
$t->cell(1,2)->push_content(em("Monday 1st DOW", br,
			       "plus week of year count"));
$t->cell(1,3)->push_content(em("Deutsch aliased"));
# Populate container table
foreach (0..$#cals) {
   $t->cell(0,$_)->push_content($cals[$_]);
}
print $t->as_HTML;

Four calendars illustrating 1st day of week, week of year count, and aliasing options.

         
March2000
SuMTuWThFSa
      1234
567891011
12131415161718
19202122232425
262728293031 
         
March2000
MTuWThFSaSu
    12345
6789101112
13141516171819
20212223242526
2728293031   
           
March2000
MTuWThFSaSu 
    123459
678910111210
1314151617181911
2021222324252612
2728293031    13
           
März2000
MoDiMiDoFSaSo 
    123459
678910111210
1314151617181911
2021222324252612
2728293031    13
DefaultMonday 1st
Day Of Week
Monday 1st DOW
plus week of year count
Deutsch aliased

# Calendars are a super class of HTML::ElementTable, and thereby
# inherit all of its methods, including those of HTML::ElementSuper
# such as clone().  For debugging purposes, you can easily display
# the table coordinates in every calendar cell.

$cal_a = new HTML::CalendarMonth ( week_begin => 2,
				   head_week  => 1, );
# Embolden headers
$cal_a->item($cal_a->month, $cal_a->year)->wrap_content(font({size => '+2'}));
# Illustrate week number headers
$cal_a->item_week_nums->wrap_content(font({'size' => '-1'}));
$cal_a->item_week_nums->attr(bgcolor => 'cyan');

# Clone first calendar
$cal_b = $cal_a->clone;

# Display debugging coordinates in clone
$cal_b->all->push_position;

# Generate container table
$t = new HTML::ElementTable ( maxrow => 1, maxcol => 1 );
$t->row(0)->attr(valign => 'bottom');
$t->row(1)->attr(align  => 'middle');
$t->cell(1,0)->push_content(em("Normal"));
$t->cell(1,1)->push_content(em("Clone with debugging coordinates (used with",
			       br(), "HTML::ElementTable methods)"));
# Populate container table
$t->cell(0,0)->push_content($cal_a);
$t->cell(0,1)->push_content($cal_b);

print $t->as_HTML;

Two calendars illustrating cloning and debugging behavior inherited from HTML::ElementTable

           
January2000
MTuWThFSaSu 
          1252
34567891
101112131415162
171819202122233
242526272829304
31            5
           
January (0,0)2000 (0,6)
M (1,0)Tu (1,1)W (1,2)Th (1,3)F (1,4)Sa (1,5)Su (1,6) (1,7)
(2,0) (2,1) (2,2) (2,3) (2,4)1 (2,5)2 (2,6)52 (2,7)
3 (3,0)4 (3,1)5 (3,2)6 (3,3)7 (3,4)8 (3,5)9 (3,6)1 (3,7)
10 (4,0)11 (4,1)12 (4,2)13 (4,3)14 (4,4)15 (4,5)16 (4,6)2 (4,7)
17 (5,0)18 (5,1)19 (5,2)20 (5,3)21 (5,4)22 (5,5)23 (5,6)3 (5,7)
24 (6,0)25 (6,1)26 (6,2)27 (6,3)28 (6,4)29 (6,5)30 (6,6)4 (6,7)
31 (7,0) (7,1) (7,2) (7,3) (7,4) (7,5) (7,6)5 (7,7)
NormalClone with debugging coordinates (used with
HTML::ElementTable methods)

Back to description
sisk@mojotoad.com