Browse Source

Merge pull request #8685 from cakephp/datetime-jsonencode

Date json encode format
Mark Story 10 years ago
parent
commit
87ba9c7379

+ 1 - 1
.travis.yml

@@ -61,7 +61,7 @@ before_install:
   - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi"
   - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE SCHEMA test2;' -U postgres -d cakephp_test; fi"
   - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE SCHEMA test3;' -U postgres -d cakephp_test; fi"
-  
+
   - if [[ $TRAVIS_PHP_VERSION != 'hhvm' ]] ; then pecl channel-update pecl.php.net; fi;
 
   - if [[ $TRAVIS_PHP_VERSION != 'hhvm' ]] ; then echo 'extension = memcached.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi

+ 1 - 1
src/I18n/DateFormatTrait.php

@@ -54,7 +54,7 @@ trait DateFormatTrait
      * @var string|array|int
      * @see \Cake\I18n\Time::i18nFormat()
      */
-    protected static $_jsonEncodeFormat = "yyyy-MM-dd'T'HH:mm:ssZ";
+    protected static $_jsonEncodeFormat = "yyyy-MM-dd'T'HH:mm:ssxxx";
 
     /**
      * Caches whether or not this class is a subclass of a Date or MutableDate

+ 5 - 1
tests/TestCase/I18n/DateTest.php

@@ -150,8 +150,12 @@ class DateTest extends TestCase
      */
     public function testJsonSerialize($class)
     {
+        if (version_compare(INTL_ICU_VERSION, '50.0', '<')) {
+            $this->markTestSkipped('ICU 5x is needed');
+        }
+
         $date = new $class('2015-11-06 11:32:45');
-        $this->assertEquals('"2015-11-06T00:00:00+0000"', json_encode($date));
+        $this->assertEquals('"2015-11-06T00:00:00+00:00"', json_encode($date));
     }
 
     /**

+ 5 - 1
tests/TestCase/I18n/TimeTest.php

@@ -710,8 +710,12 @@ class TimeTest extends TestCase
      */
     public function testJsonEnconde($class)
     {
+        if (version_compare(INTL_ICU_VERSION, '50.0', '<')) {
+            $this->markTestSkipped('ICU 5x is needed');
+        }
+
         $time = new $class('2014-04-20 10:10:10');
-        $this->assertEquals('"2014-04-20T10:10:10+0000"', json_encode($time));
+        $this->assertEquals('"2014-04-20T10:10:10+00:00"', json_encode($time));
 
         $class::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss');
         $this->assertEquals('"2014-04-20 10:10:10"', json_encode($time));