[Edinburgh-pm] Heresy

Aaron Crane perl at aaroncrane.co.uk
Tue Apr 21 12:46:35 PDT 2009


Orthodoxy tells us that we meet on the fourth Thursday of each month.

A vile sect of heretics hold their furtive sabbats on the last Thursday
of the month, despite the teachings of our holy books that calendaring
software can't handle such recurrences.

In the interest of freedom of religious conscience for all, I note
that Thursday April 30th is such a heretical date.  Anyone in need of
reminders for such events in the future may wish to use this:

  http://aaroncrane.co.uk/edinburgh_heretics.ics

The program I used to generate it is attached; if you'd like it to do
something different, patches welcome!

-- 
Aaron Crane ** http://aaroncrane.co.uk/
-------------- next part --------------
#! /usr/bin/perl

use strict;
use warnings;

use DateTime;
use Template;
use List::MoreUtils qw<apply>;

my $first_of_month =
    DateTime->today(time_zone => 'Europe/London')->truncate(to => 'month');

my @events;
while (@events < 5) {
    # Find the last day of the month in question
    my $day = DateTime->last_day_of_month(
        year      => $first_of_month->year,
        month     => $first_of_month->month,
        time_zone => $first_of_month->time_zone,
    );

    # Step backwards until we're looking at a Thursday
    $day->subtract(days => 1)
        while $day->wday != 4;

    # And if it's actually the *fifth* Thursday, then we're in business
    if (suitable_date($day)) {
        my $start = $day->clone->set(
            hour   => 19,
            minute => 30,
        );
        $start->set_time_zone('UTC');
        my $end = $start->clone->add(hours => 4, minutes => 30);
        push @events, { start => $start, end => $end };
    }

    $first_of_month->add(months => 1);
}

sub suitable_date {
    my ($date) = @_;
    return $date->weekday_of_month == 5
        && ($date->month != 12 || $date->day != 31);
}

my $template = apply { s/(?<!\r)(?=\n)/\r/g } <<'EOF';
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Ad-hoc Perl//NONSGML v0.1//EN
BEGIN:VTIMEZONE
END:VTIMEZONE
[% FOR e = events %]BEGIN:VEVENT
DTSTART:[% e.start.strftime('%Y%m%dT%H%M%SZ') %]
DTEND:[% e.end.strftime('%Y%m%dT%H%M%SZ') %]
CLASS:PUBLIC
SUMMARY:Edinburgh.pm Heretics meeting, [% e.start.strftime('%B %Y') %]
GEO:55.95384;-3.19008
LOCATION;ALTREP="http://www.guildfordarms.com/":
 The Guildford Arms, West Register Street, Edinburgh EH2 2AA
END:VEVENT
[% END %]END:VCALENDAR
EOF

my $tt = Template->new;
$tt->process(\$template, { events => \@events })
    or die $tt->error, "\n";


More information about the Edinburgh-pm mailing list