iCal::Parser(3pm)

πŸ’– iCal::Parser πŸ’–

okay bestie, so this is the iCal::Parser manual page β€” it lives in the User Contributed Perl Documentation section, and it's giving 3pm energy. it's literally the whole vibe of "parse iCalendar files into a data structure" and i'm obsessed. let's get into it 🫢


✨ NAME ✨

iCal::Parser β€” parse iCalendar files into a data structure πŸŽ€


✨ SYNOPSIS ✨

use iCal::Parser;

my $parser=iCal::Parser->new();
my $hash=$parser->parse($file);

$parser->parse($another_file);
my $combined=$parser->calendar;

my $combined=iCal::Parser->new->parse(@files);
my $combined=iCal::Parser->new->parse_files(@files);
my $combined=iCal::Parser->new->parse_strings(@strings);

like. look at her. five different ways to do the thing, all slaying πŸ’…


✨ DESCRIPTION ✨

so this module takes iCalendar (vCalendar 2.0) files β€” the ones specified in RFC 2445 β€” and turns them into a data structure. periodt. 🌈

what does it handle? bestie, listen:

  • recurrences, aka RRULEs
  • exclusions, aka EXDATEs
  • event updates (events with a RECURRENCE-ID)
  • nested data structures (ATTENDEES and VALARMs)

and what is it currently ignoring, you ask? the VTIMEZONE, VJOURNAL and VFREEBUSY entry types. it's just not their era yet πŸ’€

the data structure it gives you back is a hash like this:

{
  calendars=>[\%cal, ...],
  events=>{yyyy=>{mm=>{dd}=>{UID=>\%event}}
  todos=>[\%todo, ...]
}

so yeah: an array of calendar hashes, a hash of events keyed by year=>month=>day=>eventUID, and an array of todos. three mains, one struct. main character structure fr 🧚

Calendars, events and todos are "rolled up" version os the hashes returned from Text::vFile::asData, with dates replaced by DateTime objects.

important part, don't scroll past: during parsing, events in the input calendar get expanded out into multiple events β€” one per day covered by the event. here's exactly how, no cap:

  • If the event is a one day "all day" event (in ical, the event is 24hrs long, starts at midnight on the day and ends a midnight of the next day), it contains no hour field and the allday field is set to 1.
  • If the event is a recurrence (RRULE), one event per day is created as per the RRULE specification.
  • If the event spans more than one day (the start and end dates are on different days, but does not contain an RRULE), it is expanded into multiple events, the first events end time is set to midnight, subsequent events are set to start at midnight and end at midnight the following day (same as an allday event, but the allday field is not set), and the last days event is set to run from midnight to the end time of the original multi-day event.
  • If the event is an update (it contains a RECURRENCE-ID), the original event is updated. If the referenced event does not exist (e.g., it was deleted after the update), then the event is added as a new event.

an example of each hash is below. πŸ‘‡


πŸ¦‹ Calendar Hash πŸ¦‹

{
    'X-WR-CALNAME' => 'Test',
    'index' => 1,
    'X-WR-RELCALID' => '7CCE8555-3516-11D9-8A43-000D93C45D90',
    'PRODID' => '-//Apple Computer\\, Inc//iCal 1.5//EN',
    'CALSCALE' => 'GREGORIAN',
    'X-WR-TIMEZONE' => 'America/New_York',
    'X-WR-CALDESC' => 'My Test Calendar',
    'VERSION' => '2.0'
}

🌸 Event Hash 🌸

ok so note this: hours and allday are mutually exclusive in the actual data. like, they do not coexist, they do not share a room. and the idref field contains the id of the calendar the event came from β€” which is super useful if the hash was created from multiple calendars. multi-calendar queen πŸ‘‘

{
    'SUMMARY' => 'overnight',
    'hours' => '15.00',
    'allday' => 1,
    'UID' => '95CCBF98-3685-11D9-8CA5-000D93C45D90',
    'idref' => '7CCE8555-3516-11D9-8A43-000D93C45D90',
    'DTSTAMP' => \%DateTime,
    'DTEND' => \%DateTime,
    'DTSTART' => \%DateTime
    'ATTENDEE' => [
       {
          'CN' => 'Jay',
          'value' => 'mailto:jayl@my.server'
       },
      ],
      'VALARM' => [
        {
          'when' => \%DateTime,
          'SUMMARY' => 'Alarm notification',
          'ACTION' => 'EMAIL',
          'DESCRIPTION' => 'This is an event reminder',
          'ATTENDEE' => [
             {
               'value' => 'mailto:cpan@my.server'
             }
          ]
        }
      ],
}

πŸ“ Todo Hash πŸ“

{
    'URL' => 'mailto:me',
    'SUMMARY' => 'todo 1',
    'UID' => 'B78E68F2-35E7-11D9-9E64-000D93C45D90',
    'idref' => '7CCE8555-3516-11D9-8A43-000D93C45D90',
    'STATUS' => 'COMPLETED',
    'COMPLETED' => \%DateTime,
    'DTSTAMP' => \%DateTime,
    'PRIORITY' => '9',
    'DTSTART' => \%DateTime,
    'DUE' => \%DateTime,
    'DESCRIPTION' => 'not much',
    'VALARM' => [
       {
          'when' => \%DateTime,
          'ATTACH' => 'file://localhost/my-file',
          'ACTION' => 'PROCEDURE'
       }
    ],
},

✨ Methods ✨

πŸ’œ new(%opt_args) πŸ’œ

ok so here are the optional arguments, bestie. every single one, no skipping:

  • start {yyymmdd|DateTime} β€” only include events on or after yyymmdd. defaults to Jan of this year. (yes, january. this year. that's the default, don't @ me)
  • end {yyyymmdd|DateTime} β€” only include events before yyymmdd.
  • no_events β€” don't include events in the output (todos only).
  • no_todos β€” don't include todos in the output (events only).
  • months n β€” DateTime::Sets (used for calculating recurrences) are limited to approximately 200 entries. If an end date is not specified, the to date is set to the start date plus this many months. the default is 60.
  • tz (string|DateTime::TimeZone) β€” use tz as timezone for date values. the default is 'local', which will adjust the parsed dates to the current timezone.
  • debug β€” set to non-zero for some debugging output during processing. spy on her, she's fine with it πŸ”₯

πŸ’œ parse({file|file_handle}+) πŸ’œ

Parse the input files or opened file handles and return the generated hash.

This function can be called mutitple times and the calendars will be merge into the hash, each event tagged with the unique id of its calendar.

πŸ’œ parse_files({file|file_handle}+) πŸ’œ

Alias for parse() β€” same girl, different name πŸ’…

πŸ’œ parse_strings(string+) πŸ’œ

Parse the input strings (each assumed to be a valid iCalendar) and return the generated hash.


✨ AUTHOR ✨

Rick Frankel, cpan@rickster.com β€” thank you for your service king 🫢


This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

bestie this is the "free software" part so you can absolutely use it, copy it, remix it β€” just read the LICENSE file for the full deets πŸ’–

✨ SEE ALSO ✨

  • Text::vFile::asData
  • DateTime::Set
  • DateTime::Span
  • iCal::Parser::SAX

the whole friend group, all iconic, all worth a follow 🌟


k that's the whole page bestie, you're officially iCal-pilled πŸ’…βœ¨

this masterpiece was served to you by perl v5.40.1, dated 2025-03-01, and it lives at iCal::Parser(3pm) β€” go forth and parse, you absolute icon πŸ‘‘πŸ¦‹πŸ’–

πŸ“¦ where this page comes from