[Pkg-owncloud-commits] [php-sabre-vobject] 10/43: Adding a property for dates with unknown year

David Prévot taffit at moszumanska.debian.org
Sat Sep 5 15:23:47 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to tag 4.0.0-alpha2
in repository php-sabre-vobject.

commit cc13ef04eebc6c05e356aa08516e0fb43363b3a1
Author: Dominik Tobschall <dominik at fruux.com>
Date:   Mon Jul 20 09:25:50 2015 +0200

    Adding a property for dates with unknown year
---
 lib/BirthdayCalendarGenerator.php               | 23 ++++++++++++++++-------
 tests/VObject/BirthdayCalendarGeneratorTest.php |  8 ++++----
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/lib/BirthdayCalendarGenerator.php b/lib/BirthdayCalendarGenerator.php
index 3aecff8..bd04a70 100644
--- a/lib/BirthdayCalendarGenerator.php
+++ b/lib/BirthdayCalendarGenerator.php
@@ -42,7 +42,7 @@ class BirthdayCalendarGenerator {
      *
      * @var int
      */
-    protected $defaultYear = 1900;
+    protected $defaultYear = 2000;
 
     /**
      * Output format for the SUMMARY.
@@ -173,11 +173,12 @@ class BirthdayCalendarGenerator {
             }
 
             // Set a year if it's not set.
+            $unknownYear = false;
+
             if (!$dateParts['year']) {
                 $object->BDAY = $this->defaultYear . '-' . $dateParts['month'] . '-' . $dateParts['date'];
 
-                // @TODO:
-                // It may make sense to add an info to our event that the year was unknown.
+                $unknownYear = true;
             }
 
             // Create event.
@@ -189,10 +190,18 @@ class BirthdayCalendarGenerator {
             ]);
 
             // Add X-SABRE-BDAY property.
-            $event->add('X-SABRE-BDAY', 'BDAY', [
-                'X-SABRE-VCARD-UID' => $object->UID->getValue(),
-                'X-SABRE-VCARD-FN'  => $object->FN->getValue(),
-            ]);
+            if ($unknownYear) {
+                $event->add('X-SABRE-BDAY', 'BDAY', [
+                    'X-SABRE-VCARD-UID' => $object->UID->getValue(),
+                    'X-SABRE-VCARD-FN'  => $object->FN->getValue(),
+                    'X-SABRE-OMIT-YEAR' => $this->defaultYear,
+                ]);
+            } else {
+                $event->add('X-SABRE-BDAY', 'BDAY', [
+                    'X-SABRE-VCARD-UID' => $object->UID->getValue(),
+                    'X-SABRE-VCARD-FN'  => $object->FN->getValue(),
+                ]);
+            }
 
         }
 
diff --git a/tests/VObject/BirthdayCalendarGeneratorTest.php b/tests/VObject/BirthdayCalendarGeneratorTest.php
index 3108ba6..18e8055 100644
--- a/tests/VObject/BirthdayCalendarGeneratorTest.php
+++ b/tests/VObject/BirthdayCalendarGeneratorTest.php
@@ -209,10 +209,10 @@ BEGIN:VCALENDAR
 VERSION:2.0
 BEGIN:VEVENT
 SUMMARY:Forrest Gump's Birthday
-DTSTART:19000407T000000Z
+DTSTART:20000407T000000Z
 RRULE:FREQ=YEARLY
 TRANSP:TRANSPARENT
-X-SABRE-BDAY;X-SABRE-VCARD-UID=foo;X-SABRE-VCARD-FN=Forrest Gump:BDAY
+X-SABRE-BDAY;X-SABRE-VCARD-UID=foo;X-SABRE-VCARD-FN=Forrest Gump;X-SABRE-OMIT-YEAR=2000:BDAY
 END:VEVENT
 END:VCALENDAR
 ICS;
@@ -244,10 +244,10 @@ BEGIN:VCALENDAR
 VERSION:2.0
 BEGIN:VEVENT
 SUMMARY:Forrest Gump's Birthday
-DTSTART:19000407T000000Z
+DTSTART:20000407T000000Z
 RRULE:FREQ=YEARLY
 TRANSP:TRANSPARENT
-X-SABRE-BDAY;X-SABRE-VCARD-UID=foo;X-SABRE-VCARD-FN=Forrest Gump:BDAY
+X-SABRE-BDAY;X-SABRE-VCARD-UID=foo;X-SABRE-VCARD-FN=Forrest Gump;X-SABRE-OMIT-YEAR=2000:BDAY
 END:VEVENT
 END:VCALENDAR
 ICS;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabre-vobject.git



More information about the Pkg-owncloud-commits mailing list