[Pkg-owncloud-commits] [php-sabre-vobject] 34/46: Fix encoding/decoding of TIME values in jCard/jCal.

David Prévot taffit at moszumanska.debian.org
Thu Dec 10 02:12:41 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 35c25dcc8b93cd88c91a1a22090d09447a2bd5b9
Author: Evert Pot <me at evertpot.com>
Date:   Thu Nov 26 01:16:35 2015 -0500

    Fix encoding/decoding of TIME values in jCard/jCal.
    
    Fixes #185
---
 CHANGELOG.md                      |  1 +
 lib/Property/Time.php             | 33 ++++++++++++++++++++++++++++++++-
 tests/VObject/Parser/JsonTest.php |  8 ++++----
 3 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 01822ba..f983d35 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ ChangeLog
 * #220: Automatically stop recurring after 3500 recurrences.
 * #41: Allow user to set different encoding than UTF-8 when decoding vCards.
 * #41: Support the `ENCODING` parameter from vCard 2.1.
+* #185: Fix encoding/decoding of `TIME` values in jCal/jCard.
 
 
 4.0.0-alpha2 (2015-09-04)
diff --git a/lib/Property/Time.php b/lib/Property/Time.php
index 8664332..409af21 100644
--- a/lib/Property/Time.php
+++ b/lib/Property/Time.php
@@ -38,6 +38,32 @@ class Time extends Text {
     }
 
     /**
+     * Sets the JSON value, as it would appear in a jCard or jCal object.
+     *
+     * The value must always be an array.
+     *
+     * @param array $value
+     *
+     * @return void
+     */
+    function setJsonValue(array $value) {
+
+        // Removing colons from value.
+        $value = str_replace(
+            ':',
+            '',
+            $value
+        );
+
+        if (count($value) === 1) {
+            $this->setValue(reset($value));
+        } else {
+            $this->setValue($value);
+        }
+
+    }
+
+    /**
      * Returns the value, in the format it should be encoded for json.
      *
      * This method must always return an array.
@@ -83,7 +109,12 @@ class Time extends Text {
 
         // Timezone
         if (!is_null($parts['timezone'])) {
-            $timeStr .= $parts['timezone'];
+            if ($parts['timezone'] === 'Z') {
+                $timeStr .= 'Z';
+            } else {
+                $timeStr .=
+                    preg_replace('/([0-9]{2})([0-9]{2})$/', '$1:$2', $parts['timezone']);
+            }
         }
 
         return [$timeStr];
diff --git a/tests/VObject/Parser/JsonTest.php b/tests/VObject/Parser/JsonTest.php
index 1814dde..c8725df 100644
--- a/tests/VObject/Parser/JsonTest.php
+++ b/tests/VObject/Parser/JsonTest.php
@@ -177,9 +177,9 @@ item1.TEL:+1 555 123456
 item1.X-AB-LABEL:Walkie Talkie
 ADR:;;My Street,Left Side,Second Shack;Hometown;PA;18252;U.S.A
 X-TRUNCATED;VALUE=DATE:--12-25
-X-TIME-LOCAL;VALUE=TIME:12:30:00
-X-TIME-UTC;VALUE=TIME:12:30:00Z
-X-TIME-OFFSET;VALUE=TIME:12:30:00-08:00
+X-TIME-LOCAL;VALUE=TIME:123000
+X-TIME-UTC;VALUE=TIME:123000Z
+X-TIME-OFFSET;VALUE=TIME:123000-0800
 X-TIME-REDUCED;VALUE=TIME:23
 X-TIME-TRUNCATED;VALUE=TIME:--30
 X-KARMA-POINTS;VALUE=INTEGER:42
@@ -335,7 +335,7 @@ URL;VALUE=URI:http://example.org/
 TZOFFSETFROM:+0500
 RRULE:FREQ=WEEKLY;BYDAY=MO,TU
 X-BOOL;VALUE=BOOLEAN:TRUE
-X-TIME;VALUE=TIME:08:00:00
+X-TIME;VALUE=TIME:080000
 REQUEST-STATUS:2.0;Success
 REQUEST-STATUS:3.7;Invalid Calendar User;ATTENDEE:mailto:jsmith at example.org
 BEGIN:VALARM

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