For a long time the Chicago.pm website did not have up-to-date meeting dates. The groups meets every third Monday (tonight, for instance), so the next meeting date is not hard to calculate, but most people cannot do it very easily. We can; however, simply publish the dates so even the people who do know how to do that sort of math in their heads can check their work. Formally somebody did this by hand, and as with anything that requires human interaction, sometimes it did not happen.
The Date::* modules in Perl do some amazingly things. In Date::Manip, the ParseRecur function can compute recurring dates like "every third monday". I need to tell it a date on which the event did (or will) occur, a starting date, and an ending date. In this case, Chicago.pm had a meeting on July 15th, so that is my base date. Date::Manip understands "today" as a date, so I use that as my start date, and I want a date four months in the future (to get at least 3 upcoming meeting dates)---DateCalc understands "+ 4 months".
I also have to give thee ParseRecur function a string that describes how the event repeats, in this case "0:1*3:1:0:0:0". The "1*3" says the third thingy of every month, and the "1" following that says "Monday", the second day in the week, counting from 0. The format is a bit mind-bending, but the function's documentation has several examples.
Amazing. This is not an easy calculation, but my actual task is really easy---I can do it by hand simply by looking at my calendar. I want to automate this so I do not have to look at my calendar, not because it is hard. The Date::Manip module lets me translate the date description into a lit bit of code and it does the rest.
In the HTML I use two server-side includes---one that inserts the next meeting date, and one for the upcoming dates.
<!--#include virtual="next_meeting.txt" -->
<!--#include virtual="meeting_dates.txt" -->
I only need to get the right information into those files. I add my script to crontab and finally, in over ten years of unix experience (mostly not system administration), I get to use the weekday column of the crontab. I run the command every Monday at 9 pm (any meeting should be in progress). Three out of four times it outputs the same thing already in the files. That inefficiency is better than me forgetting to update the web page.
0 21 * * 1
The code is very simple. I love the Date::Manip module.
# save the string to replace the upcoming meeting times placeholder
# in the HTML
open FILE, ">
# Every third monday
my @dates = &ParseRecur("0:1*3:1:0:0:0",'July 15, 2002',
&DateCalc( "today","+ 4 months " )
foreach my $date ( @dates )
printf FILE qq|<li>%s\n|,
&UnixDate($date, "%B %d, %Y"),
# save the string to replace the next meeting time placeholder
# in the HTML
open FILE, ">
print FILE &UnixDate($dates, "%B %d, %Y"), " at 7:30pm";