NAME
HTML::Make::Calendar - Make an HTML calendar
SYNOPSIS
use HTML::Make::Calendar;
VERSION
This documents version 0.00_02 of HTML-Make-Calendar corresponding to git commit a5d3b639eff832faf4b4a10f4156c82dad6e2cb0 released on Sun Jan 10 11:47:38 2021 +0900.
DESCRIPTION
This module constructs HTML calendars.
FUNCTIONS
calendar
my $out = calendar (year => 2010, month => 10);
Make the calendar. The return value is an HTML::Make object. To get the actual HTML, call its text
method:
use utf8;
use FindBin '$Bin';
use HTML::Make::Calendar 'calendar';
my $out = calendar (year => 2021, month => 1);
print $out->text ();
The output HTML looks like this:
January 2021 | ||||||
---|---|---|---|---|---|---|
Mo | Tu | We | Th | Fr | Sa | Su |
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 |
(This example is included as calendar.pl in the distribution.)
The possible arguments are
- cdata
-
Callback data, see "dayc".
- dayc
-
Day callback. If this is omitted, a default element is added. The day callback is called with three arguments, first "cdata", second the date as a hash reference with arguments
year
,month
anddom
(day of month, a number from 1 to 31), and third the HTML element to attach the return value to, representing the cell of the calendar.&{$dayc} ($cdata, {year => 2020, month => 12, day => 21}, $td);
where
$td
is an HTML::Make object. - month
-
The month, as a number from 1 to 12. If the month is omitted, the current month is used as given by "Today" in Date::Calc.
- year
-
The year, as a four-digit number like
2020
. If the year is omitted, the current year is used, as given by "Today" in Date::Calc.
Daily menu
This example demonstrates the use of "dayc" and "cdata".
use utf8;
use FindBin '$Bin';
use HTML::Make::Calendar 'calendar';
my @food = split '', '🍇🍈🍉🍊🍋🍌🍍🥭🍎🍏🍐🍑🍒🍓🥝🍅🥝🍅🥒🥬🥦🧄🧅🍄🥜🌰';
my $cal = calendar (cdata => \@food, dayc => \&add_food);
print $cal->text ();
exit;
sub add_food
{
my ($food, $date, $element) = @_;
my $today = $food->[int (rand (@$food))];
$element->push ('span', text => "$date->{dom} $today");
}
The output HTML looks like this:
January 2021 | ||||||
---|---|---|---|---|---|---|
Mo | Tu | We | Th | Fr | Sa | Su |
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 𥬠|
(This example is included as menu.pl in the distribution.)
Phases of the moon
This example demonstrates the use of "dayc" and "cdata" by adding the phase of the moon to your calendar. It requires Astro::MoonPhase (not included with this distribution).
use utf8;
use HTML::Make::Calendar 'calendar';
use Astro::MoonPhase;
use Date::Calc 'Date_to_Time';
my @moons = qw!🌑 🌒 🌓 🌔 🌕 🌖 🌗 🌘!;
my $cal = calendar (dayc => \&daymoon, cdata => \@moons);
print $cal->text ();
exit;
sub daymoon
{
my ($moons, $date, $element) = @_;
my $epochtime = Date_to_Time ($date->{year}, $date->{month},
$date->{dom}, 0, 0, 0);
my ($phase) = phase ($epochtime);
my $text = $moons->[int (8*$phase)] . " <b>$date->{dom}</b>";
$element->add_text ($text);
}
The output HTML looks like this:
January 2021 | ||||||
---|---|---|---|---|---|---|
Mo | Tu | We | Th | Fr | Sa | Su |
ð 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 |
(This example is included as moon.pl in the distribution.)
CSS STYLES
The elements of the calendar have the following CSS default style names:
DEPENDENCIES
- Date::Calc
-
Date::Calc supplies the date information for the calendar.
- HTML::Make
-
HTML::Make is used to generate the HTML for the calendar.
SCRIPT
See html-cal in the distribution.
SEE ALSO
Other CPAN modules
- Calendar::List
- Calendar::Schedule
- Calendar::Simple
- Date::Calendar
-
Includes a script cal2html for making HTML.
- HTML::Calendar::Monthly
-
Fork of "HTML::Calendar::Simple". The documentation is largely copy-pasted from that with some alterations.
- HTML::Calendar::Simple
- HTML::CalendarMonth
- HTML::CalendarMonthSimple
- SVG::Calendar
AUTHOR
Ben Bullock, <bkb@cpan.org>
COPYRIGHT & LICENCE
This package and associated files are copyright (C) 2021 Ben Bullock.
You can use, copy, modify and redistribute this package and associated files under the Perl Artistic Licence or the GNU General Public Licence.