#!/usr/bin/perl use strict; use warnings; use CGI qw(:standard); use Date::Calc qw(:all); use HTML::AsSubs; use HTML::Element; use HTML::CalendarMonth; # @dates has already been sorted my @dates = (730000, 731158, 731159, 731160, 731161, 731178, 735000); # Get ready for the HTML content! print header(), start_html(-title => "Calendars"); # As long as there is a date left in @dates while (defined $dates[0]) { # get the first value from @dates leaving @dates alone my $days = $dates[0]; # find out the year, month and day so we can create a calendar my ($year, $month, $day) = Add_Delta_Days(1,1,1, $days - 1); # run the CreateCal subroutine with the year and month from the first date # store the returned value in @dates so it can be used the next time through the while loop @dates = CreateCal($year, $month, @dates); } # finish up the HTML print end_html(); exit(0); sub CreateCal { # Get the year and month for the calendar # as well as the @dates to use my ($cyear, $cmonth, @dates) = @_; # set up some variables that are local to this subroutine my (@days, @temp); # Process each $days in @dates foreach my $days (@dates) { # Get the year, month and day of $days my ($year, $month, $day) = Add_Delta_Days(1,1,1, $days - 1); # does it match the calendar we are creating? if ($year == $cyear && $month == $cmonth) { # if yes, then add the $day to @days push (@days, $day); } else { # if no, then add the $days to @temp push (@temp, $days); } } # create a new HTML::CalendarMonth using the year and month passed into the subroutine my $c = new HTML::CalendarMonth( month => $cmonth, year => $cyear, ); # setup the display options $c->item($c->month)->wrap_content(font({size => '+2'})); $c->item($c->dayheaders)->wrap_content(font({size => '-1'})); # change the background color of the @days to wheat $c->item(@days)->attr(bgcolor => 'wheat'); # create a new paragraph containing the calendar print "
", $c->as_HTML, "
"; # return the dates that are not a part of this calendar return @temp; }