Log in

No account? Create an account

Fri, Aug. 5th, 2005, 01:00 pm

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.