Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table based calendar?

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi,

I'm really struggling with this :(

It seems there are none (at least, that I can find) decent Perl modules for making a table based calendar.

At the moment, I have bodged some stuff together -;

Code:
#!/usr/bin/perl


   use CGI::Carp qw(fatalsToBrowser);
   print "Content-Type: text/html \n\n";

   use Date::Calc qw(
       Days_in_Year
       Days_in_Month
       Calendar
   );

   my $cal = Date::Calc::Calendar(2007,8);

   print $cal;

#   $cal =~ s| (\d+)|<a href="$1">$1</a>|sig;

   my @tmp = split /\n/, $cal;    

#   $tmp[3];

   my $back;
   for (my $i = 3; $i <= 7; $i++) {
      my $show = $tmp[$i];
      $show =~ s| (\d+)|<td width="25" align="center"><a href="$1">$1</a></td>|sig;      
      $back .= "<tr>" .$show . "</tr>\n";
   }

   print qq|<table border="1" style="border-collapse: collapse">
	<tr>
		<td width="25" align="center"><b>Sun</b></td>
		<td width="25" align="center"><b>Mon</b></td>
		<td width="25" align="center"><b>Tue</b></td>
		<td width="25" align="center"><b>Wed</b></td>
		<td width="25" align="center"><b>Thur</b></td>
		<td width="25" align="center"><b>Fri </b> </td>
		<td width="25" align="center"><b>Sat</b></td>
	</tr>
$back
</table>|;

However, this doesn't take into consideration the <td></td> data for blank spots (i.e when the date doesn't start on a monday).

Has anyone seen any good perl modules / good code for making a box type calendar? Like you get with Date::Calc::Calendar(yyyy,mm) , but in a table (it needs to be shown on a HTML page, so having just a plain test one isn't any good to me :(

TIA - I've been racking my brain over this for a good 4 days now, and the above code is about as close as I've got :(

Cheers
 
I use Calendar::Simple

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Hi,

Thanks for the reply, I've asked my host to install this module.

Does this format in HTML tables? Thats the main problem I've had with Date::Calc, as it only formats it in simple plain text - which is ok generally, but I need to show it on a HTML page - so its proving a real PITA to get the formatting of it right (as in my above code)

TIA

Andy
 
You know.. I might have lied.. I glanced at the code and thought calendar::simple was doing the html but realized I had coded it all in around it. There is a html::calendar::simple but I have never used it. Sorry to mis-inform you.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Hi,

No problem - I asked them to install that too, as my host just installed the module, and it does exactly the same as Date::Calc::Calendar() <G>

Hopefully HTML::Calendar::Simple will be up to more :)

Thanks for the heads up though - it looks like the HTML one will work better :)

Cheers

Andy
 
I checked out Calendar::Simple and it seems easy to work with:

Code:
[root@upsilon ~]# perl
use Calendar::Simple;
use Data::Dumper;

my @curr = calendar;
print Dumper(\@curr);
__END__
$VAR1 = [
          [
            undef,
            undef,
            undef,
            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,
            undef
          ]
        ];
[root@upsilon ~]#

To make the code neater:

Code:
$VAR1 = [
   [  ?,  ?,  ?,  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, ?  ],
];

Looks like a calendar to me! (I used ? for undef to save on space here). So you can just loop through the array of arrays, and you even know when to make an empty table cell.

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
Hi,

Thanks - that looks interesting. I'm guessing the following:

my @curr = calendar;

Can have the params passed in?

i.e

my @curr = calendar($y,$m);

?

TIA for your help :)

Cheers

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top