Simon Wistow (deflatermouse) wrote,
Simon Wistow
deflatermouse

Data::ICal::DateTime

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.

Tags: convenience, cpan, datetime, day events, endtime, explode, faked, ical, nanosecond, periods, recurring events, spans, trumpet
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments