Selaa lähdekoodia

[Locale] support for z (timezone offset from GMT)

Igor Wiedler 14 vuotta sitten
vanhempi
commit
cbfaaef76e

+ 5 - 1
src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php

@@ -49,7 +49,7 @@ class StubIntlDateFormatter
         $dateTime->setTimestamp($timestamp);
         $dateTime->setTimezone($this->dateTimeZone);
 
-        $specialChars = 'MLydGQqhDEaHkKms';
+        $specialChars = 'MLydGQqhDEaHkKmsz';
         $specialCharsArray = str_split($specialChars);
         $specialCharsMatch = implode('|', array_map(function($char) {
             return $char . '+';
@@ -178,6 +178,10 @@ class StubIntlDateFormatter
                     $secondOfMinute = (int) $dateTime->format('s');
                     return str_pad($secondOfMinute, $length, '0', STR_PAD_LEFT);
                     break;
+
+                case 'z':
+                    return $dateTime->format('\G\M\TP');
+                    break;
             }
         };
 

+ 7 - 0
tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php

@@ -182,6 +182,13 @@ class StubIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
             array('s', 3601, '1'),
             array('s', 3630, '30'),
             array('s', 43200, '0'), // 12 hours
+
+            /* timezone */
+            array('z', 0, 'GMT+00:00'),
+            array('zz', 0, 'GMT+00:00'),
+            array('zzz', 0, 'GMT+00:00'),
+            array('zzzz', 0, 'GMT+00:00'),
+            array('zzzzz', 0, 'GMT+00:00'),
         );
     }