I got an email from someone asking for help building a 2-d array that models the weeks and days in a month. My standard response to questions like this is "check CPAN", but when I checked, I couldn't find something that did just what I wanted. There were plenty that did over-complex things like build HTML tables of months, but nothing that just creates the underlying data structure.
So I wrote one. It's called Calendar::Simple. Here's an example of how you'd use it to write a replacement for the Unix cal utility.
#!/usr/bin/perl -w use strict; use Calendar::Simple; my @months = qw(January February March April May June July August September October November December); my $mon = shift || ((localtime)[4] + 1); my $yr = shift || ((localtime)[5] + 1900); my @month = calendar($mon, $yr); print "\n$months[$mon - 1] $yr\n\n"; print "Su Mo Tu We Th Fr Sa\n"; foreach (@month) { print map { $_ ? sprintf "%2d ", $_ : ' ' } @$_; print "\n"; }
It's currently winging its way to CPAN, but in the meantime you can get it from http://dave.org.uk/modules/.
Re:yay, more time date related modules
2shortplanks on 2002-07-15T12:24:12
Why isn't this Date::CalendarSimple or something. If I search "Date" I'm not going to find it.Re:yay, more time date related modules
davorg on 2002-07-15T13:08:42
Erm... because either a) it's got nothing to do with dates, it's about weeks and months and stuff... of b) I just didn't think it thru enough
:)