August 5th, 2005

diesel, learning, evil, sweeti


Then, cos I was on a roll and blowing my own trumpet (not as easy as it sounds) I knocked together Data::ICal::DateTime which should go on CPAN as soon as Jesse releases my patched version of Data::ICal.

In short it uses mixins to define some convenience methods for Data::ICal and Data::ICal::Entry::Event for dealing with DateTime.

What that means is that

    # performs mixin voodoo
    use Data::ICal::DateTime;
    my $cal    = Data::ICal->new('example.ics');
    my $date1  = DateTime->new( year => 2005, month => 7, day => 01 );
    my $date2  = DateTime->new( year => 2005, month => 7, day => 07 );
    my $span   = DateTime::Span->from_datetimes( start => $date1, end => $date2 );
    my @events = $cal->events();            # all VEVENTS
    my @week   = $cal->events($span);       # just in that week
    my @week   = $cal->events($span,'day'); # explode long events into days

If you pass a period of time into events then it will return all the events in a calendar that fall within that period including any instances of recurring events that might happen (so if you have an event that recurs daily and you pass in a week then you'll get 7 faked events with the start and endtime for eahc instance calculated).

It also allows you to pass in a period of time - currently year, month, week, day, hour, minute, second, or nanosecond - and if an event spans multiple periods then it will explode them (so a two day event will become 2 one day events starting a nanosecond after each other).

I'm quite chuffed with it.

diesel, learning, evil, sweeti


Perl is weird. I mean, I know a lot of people think that it's weird full stop but sometimes it really suffers from the opensource malaise - the glaring holes in functionality that everyone knows about but no-one seems to want to fix -PGP is a particular favourite of mine. SOAP::Lite seems to be another massive bug bear. For ages, until the DateTime suite of modules came along, dates and, err, times were like that. I could go on.

ICalendar used to be like that. There was Reefknot - a sort of attempt to do calendaring stuff in Perl which produced Net::ICal and Text::vFile which sort of read .ics files. But, to be frank, they were all shit.

The mighty Richard Clamp did Text::vFile::asData which parsed a file into a loose data structure but it wasn't until Jesse 'RT' Vincent mentioned to me that he'd been writing Data::ICal which had a proper object model and a handy as_string method that things began looking up. But Data::ICal couldn't parse. Which sort of sucked.

Clearly the only avenue open for a good open source citizen was to weave together Text::vFile::asData and Data::ICal which LO! I did. And sorted out their timezone support. And even added tests because I'm attempting to be angelic in a test-driven kind of way. So now Perl has a sensible, easy to use ICalendar module can which round trip an .ics file. HUZZAH!.