Mai 2013 Archives

+2013-05-22 Mi 15:44

sorting iCal files

My experience with computers taught me to never trust computers (nor humans hahaha). So, after setting up my very own ownCloud instance I needed to find a manageable way to backup my contacts and calendars. Database backups are one way to do it but ownCloud is nice enough to offer an iCal export of the defined calendars.

After writing a backup script for automatic nightly iCal exports I wanted to find the diffs compared to other backups. Unfortunately one cannot rely on a certain order of the tags inside VEVENT blocks (every tool does it differently). That's why I wrote ical-sort.pl which not only sorts the tags inside VEVENTs. It also does a smart chronological sort of all VEVENTs inside an iCalendar file. I call it smart because it takes care of recurring events. Actually, here is what it does exactly to find a good sort order:
  • sort tags inside VEVENTs alphabetically (with some useful exeptions)
  • sort the list of VEVENTs chronologically:
    • single events sorted by DTEND field
    • repeated DAILY events sorted by UNTIL or DTEND + INTERVAL*COUNT
    • repeated WEEKLY events sorted by UNTIL or DTEND + INTERVAL*COUNT weeks
    • repeated MONTHLY events sorted by UNTIL or DTEND + INTERVAL*COUNT months
    • repeated YEARLY events sorted by UNTIL or DTEND + INTERVAL*COUNT years
    • repeated events without "UNTIL" are put at the end
Now, diffs are human readable and anytime I want to get rid of old calendar entries (e.g. to speed up ownCloud) I can just delete the first couple VEVENT blocks out of the sorted file.
No risk of losing any recurring events like birthdays or holidays.

Use it if you like it!
Patches with bugfixes, enhancements or new features are welcome.



Andy auf Google+

Posted by Andy Spiegl | Permanent link | File under: Linux

Could not open input file: /var/www/spiegl.de/infolinks.php