in reply to Re: cgi calander
in thread cgi calander

Some creative urge over took me and i figured out the date calculations to go with your HTML output! ;)

use strict; use warnings; use Data::Dumper; use CGI::Pretty qw(:standard start_table end_table start_Tr end_Tr), ( +-unique_headers); #use CGI::Carp qw(fatalsToBrowser); use Date::Calc qw(Week_of_Year Monday_of_Week Add_Delta_Days Standard +_to_Business); my @day = (2007,2,10); my @week = Week_of_Year(@day); my @weeks = []; for my $delta (-15..15) { my @n_day = Add_Delta_Days(@day,$delta); #calculate which week we are in my @n_week = Week_of_Year(@n_day); #calculate the day of the week my @b_day = Standard_to_Business(@n_day); #put it in a nice array of arrayref $weeks[$n_week[0]]->[$b_day[2]-1] = $n_day[2]; } # this seemed easier than calculating the smallest week # number and subtracting that from each index @weeks = grep {defined} @weeks; print header(); print start_html (-title => "Calendar sample"); my @weekDays = qw(Mon Tue Wed Thur Fri Sat Sun); print start_table(); print Tr ({-align=>'CENTER',-valign=>'TOP'}, td (\@weekDays)); for my $week (@weeks) { print start_Tr({-align=>'CENTER',-valign=>'TOP'}); for my $date (@$week) { if (! defined $date) { print td (''); } elsif ($date == $day[2]) { print td(strong($date)); } else { print td ($date); } } print end_Tr(); } print end_html ();

___________
Eric Hodges