When I took over organising the CLUG
meetings, I managed to replace most of myself with a small
shell script (I even have the t-shirt).
Now that I'm leaving
Canberra, Steve Walsh has kindly taken over the running of the script.
So I've done a bit more work on the script, and added a public front end to it, and made an
RSS feed (my very first).
So until yesterday, to work out the fourth Thursday of the month, I'd been
calling a Perl script that used Date::Manip,
when I decided to investigate doing it with PHP natively. Tony gave me some
initial code, but I ended up with this:
function nth_day($instance, $dow, $month, $year)
{
$first_dom
= date("w", mktime(0, 0, 0, $month, 1, $year));
if ($first_dom
<= $dow) {
$first_instance = date("j", mktime(0, 0, 0, $month, 1 + ($dow - $first_dom), $year));
} else {
$first_instance = date("j", mktime(0, 0, 0, $month, 8 - ($first_dom - $dow), $year));
}
$instance_we_want =
$first_instance +
(($instance-1) * 7);
$date = date("j", mktime(0, 0, 0, $month, $instance_we_want, $year));
return $date;
}