[Pkg-owncloud-commits] [php-sabre-vobject] 241/341: Format date to xCard according to RFC6351.

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 13:35:52 UTC 2015


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

taffit pushed a commit to branch master
in repository php-sabre-vobject.

commit b8d1d0717f35d975ec595c952ebef11d58b3489a
Author: Ivan Enderlin <ivan.enderlin at hoa-project.net>
Date:   Wed Jan 28 13:36:12 2015 +0100

    Format date to xCard according to RFC6351.
---
 lib/Property/VCard/DateAndOrTime.php | 96 ++++++++++++++++++++++++++++++++++--
 1 file changed, 91 insertions(+), 5 deletions(-)

diff --git a/lib/Property/VCard/DateAndOrTime.php b/lib/Property/VCard/DateAndOrTime.php
index 779daaa..83ae196 100644
--- a/lib/Property/VCard/DateAndOrTime.php
+++ b/lib/Property/VCard/DateAndOrTime.php
@@ -2,11 +2,13 @@
 
 namespace Sabre\VObject\Property\VCard;
 
-use Sabre\VObject\DateTimeParser;
-use Sabre\VObject\Property;
-use DateTimeInterface;
-use DateTimeImmutable;
-use DateTime;
+use
+    Sabre\VObject\DateTimeParser,
+    Sabre\VObject\Property,
+    Sabre\Xml,
+    DateTimeInterface,
+    DateTimeImmutable,
+    DateTime;
 
 /**
  * DateAndOrTime property
@@ -249,6 +251,90 @@ class DateAndOrTime extends Property {
     }
 
     /**
+     * This method serializes only the value of a property. This is used to
+     * create xCard or xCal documents.
+     *
+     * @param Xml\Writer $writer  XML writer.
+     * @return void
+     */
+    protected function xmlSerializeValue(Xml\Writer $writer) {
+
+        $valueType = strtolower($this->getValueType());
+        $parts     = DateTimeParser::parseVCardDateTime($this->getValue());
+        $value     = '';
+
+        // $d = defined
+        $d = function($part) use($parts) {
+            return !is_null($parts[$part]);
+        };
+
+        // $r = read
+        $r = function($part) use($parts) {
+            return $parts[$part];
+        };
+
+        // From the Relax NG Schema.
+        //
+        // # 4.3.1
+        // value-date = element date {
+        //     xsd:string { pattern = "\d{8}|\d{4}-\d\d|--\d\d(\d\d)?|---\d\d" }
+        //   }
+        if (   ( $d('year') ||  $d('month')  ||  $d('date'))
+            && (!$d('hour') && !$d('minute') && !$d('second') && !$d('timezone'))) {
+
+            if ($d('year') && $d('month') && $d('date')) {
+                $value .= $r('year') . $r('month') . $r('date');
+            } elseif ($d('year') && $d('month') && !$d('date')) {
+                $value .= $r('year') . '-' . $r('month');
+            } elseif (!$d('year') && $d('month')) {
+                $value .= '--' . $r('month') . $r('date');
+            } elseif (!$d('year') && !$d('month') && $d('date')) {
+                $value .= '---' . $r('date');
+            }
+
+        // # 4.3.2
+        // value-time = element time {
+        //     xsd:string { pattern = "(\d\d(\d\d(\d\d)?)?|-\d\d(\d\d?)|--\d\d)"
+        //                          ~ "(Z|[+\-]\d\d(\d\d)?)?" }
+        //   }
+        } elseif (   (!$d('year') && !$d('month')  && !$d('date'))
+                  && ( $d('hour') ||  $d('minute') ||  $d('second'))) {
+
+            if ($d('hour')) {
+                $value .= $r('hour') . $r('minute') . $r('second');
+            } elseif ($d('minute')) {
+                $value .= '-' . $r('minute') . $r('second');
+            } elseif ($d('second')) {
+                $value .= '--' . $r('second');
+            }
+
+            $value .= $r('timezone');
+
+        // # 4.3.3
+        // value-date-time = element date-time {
+        //     xsd:string { pattern = "(\d{8}|--\d{4}|---\d\d)T\d\d(\d\d(\d\d)?)?"
+        //                          ~ "(Z|[+\-]\d\d(\d\d)?)?" }
+        //   }
+        } elseif ($d('date') && $d('hour')) {
+
+            if ($d('year') && $d('month') && $d('date')) {
+                $value .= $r('year') . $r('month') . $r('date');
+            } elseif (!$d('year') && $d('month') && $d('date')) {
+                $value .= '--' . $r('month') . $r('date');
+            } elseif (!$d('year') && !$d('month') && $d('date')) {
+                $value .= '---' . $r('date');
+            }
+
+            $value .= 'T' . $r('hour') . $r('minute') . $r('second') .
+                      $r('timezone');
+
+        }
+
+        $writer->writeElement($valueType, $value);
+
+    }
+
+    /**
      * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
      *
      * This has been 'unfolded', so only 1 line will be passed. Unescaping is

-- 
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