fix dates in ical and add calendar title
authorChristian Weiske <cweiske@cweiske.de>
Fri, 21 Mar 2014 16:34:07 +0000 (17:34 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 21 Mar 2014 16:34:07 +0000 (17:34 +0100)
README.rst
src/bdrem/Renderer/Ical.php

index 66d0da289402002b90258606585cbb8d4c448ad3..c910740aca33485e51ef879e9328eac20268df81 100644 (file)
@@ -24,6 +24,7 @@ Output formats
 - ASCII table
 - HTML
 - Email (text + HTML parts)
 - ASCII table
 - HTML
 - Email (text + HTML parts)
+- iCalendar
 
 
 =====
 
 
 =====
@@ -80,6 +81,17 @@ If you only want an email if there is a birthday, use ``--stoponempty``::
 Make sure your config file contains ``$mail_from`` and ``$mail_to`` settings.
 
 
 Make sure your config file contains ``$mail_from`` and ``$mail_to`` settings.
 
 
+iCalendar
+=========
+Exporting birthday events into an ics file is easy::
+
+   $ bdrem --renderer=ical > birthdays.ics
+
+It is possible to access the calendar via HTTP, too::
+
+    http://example.org/bdrem/?renderer=ical
+
+
 HTML page
 =========
 Simply point your web browser to the ``.phar`` file, or ``index.php``.
 HTML page
 =========
 Simply point your web browser to the ``.phar`` file, or ``index.php``.
index 019e2180f188bfd868ac1cb416b21cdd5c675085..f20e461a2f10d5b758c65f807d386f27691ed937 100644 (file)
@@ -35,6 +35,9 @@ class Renderer_Ical extends Renderer
     /**
      * Render the events in an iCalendar file
      *
     /**
      * Render the events in an iCalendar file
      *
+     * X-WR-CALNAME is supported by claws mail's vcalendar plugin; it
+     * uses it as title.
+     *
      * @param array $arEvents Event objects to render
      *
      * @return string iCal file
      * @param array $arEvents Event objects to render
      *
      * @return string iCal file
@@ -43,17 +46,20 @@ class Renderer_Ical extends Renderer
     {
         $s = "BEGIN:VCALENDAR\n"
             . "VERSION:2.0\n"
     {
         $s = "BEGIN:VCALENDAR\n"
             . "VERSION:2.0\n"
-            . "PRODID:-//bdrem\n";
+            . "PRODID:-//bdrem\n"
+            . "X-WR-CALNAME:birthdays\n";
         foreach ($arEvents as $event) {
             $props = array('BEGIN' => 'VEVENT');
             
             $props['UID'] = str_replace(
         foreach ($arEvents as $event) {
             $props = array('BEGIN' => 'VEVENT');
             
             $props['UID'] = str_replace(
-                array('-', '????'), array('', '0000'), $event->date
+                array('-', '????'), array('', '0000'), $event->localDate
             )
                 . '.' . $event->age
                 . '.' . md5($event->title . '/' . $event->type)
                 . '@bdrem';
             )
                 . '.' . $event->age
                 . '.' . md5($event->title . '/' . $event->type)
                 . '@bdrem';
-            $props['DTSTART']  = str_replace('-', '', $event->date);
+            // we want the zero time because it expresses midnight in every
+            // time zone
+            $props['DTSTART']  = str_replace('-', '', $event->localDate) . 'T000000';
             $props['DURATION'] = 'P1D';
             $props['SUMMARY']  = sprintf(
                 '%s - %s. %s', $event->title, $event->age, $event->type
             $props['DURATION'] = 'P1D';
             $props['SUMMARY']  = sprintf(
                 '%s - %s. %s', $event->title, $event->age, $event->type