瀏覽代碼

[Locale] support for s (second)

Igor Wiedler 14 年之前
父節點
當前提交
7efe476693

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

@@ -40,7 +40,7 @@ class StubIntlDateFormatter
 
     public function format($timestamp)
     {
-        $specialChars = 'MLydGQqhDEaHkKm';
+        $specialChars = 'MLydGQqhDEaHkKms';
         $specialCharsArray = str_split($specialChars);
         $specialCharsMatch = implode('|', array_map(function($char) {
             return $char . '+';
@@ -164,6 +164,11 @@ class StubIntlDateFormatter
                     $minuteOfHour = (int) gmdate('i', $timestamp);
                     return str_pad($minuteOfHour, $length, '0', STR_PAD_LEFT);
                     break;
+
+                case 's':
+                    $secondOfMinute = (int) gmdate('s', $timestamp);
+                    return str_pad($secondOfMinute, $length, '0', STR_PAD_LEFT);
+                    break;
             }
         };
 

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

@@ -164,6 +164,24 @@ class StubIntlDateFormatterTest extends \PHPUnit_Framework_TestCase
             array('m', 3600, '0'),
             array('m', 3660, '1'),
             array('m', 43200, '0'), // 12 hours
+
+            /* second */
+            array('s', 0, '0'),
+            array('ss', 0, '00'),
+            array('sss', 0, '000'),
+
+            array('s', 1, '1'),
+            array('s', 2, '2'),
+            array('s', 5, '5'),
+            array('s', 30, '30'),
+            array('s', 59, '59'),
+            array('s', 60, '0'),
+            array('s', 120, '0'),
+            array('s', 180, '0'),
+            array('s', 3600, '0'),
+            array('s', 3601, '1'),
+            array('s', 3630, '30'),
+            array('s', 43200, '0'), // 12 hours
         );
     }