]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[locale/ar] Fix text direction of D/M/Y formats (redo #2268)
authorIskren Chernev <iskren.chernev@gmail.com>
Mon, 4 May 2015 04:28:25 +0000 (21:28 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Mon, 4 May 2015 04:28:25 +0000 (21:28 -0700)
src/locale/ar.js
src/test/locale/ar.js

index d3a5bfcc57db3940d55bd5b3248bc3e0995c3831..689bc8f6aef30657288910deb99327228053a119 100644 (file)
@@ -70,7 +70,7 @@ export default moment.defineLocale('ar', {
     longDateFormat : {
         LT : 'HH:mm',
         LTS : 'HH:mm:ss',
-        L : 'DD/MM/YYYY',
+        L : 'D/\u200FM/\u200FYYYY',
         LL : 'D MMMM YYYY',
         LLL : 'D MMMM YYYY LT',
         LLLL : 'dddd D MMMM YYYY LT'
@@ -110,7 +110,7 @@ export default moment.defineLocale('ar', {
         yy : pluralize('y')
     },
     preparse: function (string) {
-        return string.replace(/[١٢٣٤٥٦٧٨٩٠]/g, function (match) {
+        return string.replace(/\u200f/g, '').replace(/[١٢٣٤٥٦٧٨٩٠]/g, function (match) {
             return numberMap[match];
         }).replace(/،/g, ',');
     },
index 067a1764393ad8e96b691d3e451bd811d300c807..7565e17349cf3c45d9f48273b0c88a90f84233f5 100644 (file)
@@ -52,11 +52,11 @@ test('format', function (assert) {
             ['[the] DDDo [day of the year]',       'the ٤٥ day of the year'],
             ['LT',                                 '١٥:٢٥'],
             ['LTS',                                '١٥:٢٥:٥٠'],
-            ['L',                                  '١٤/٠٢/٢٠١٠'],
+            ['L',                                  '١٤/\u200f٢/\u200f٢٠١٠'],
             ['LL',                                 '١٤ شباط فبراير ٢٠١٠'],
             ['LLL',                                '١٤ شباط فبراير ٢٠١٠ ١٥:٢٥'],
             ['LLLL',                               'الأحد ١٤ شباط فبراير ٢٠١٠ ١٥:٢٥'],
-            ['l',                                  '١٤/٢/٢٠١٠'],
+            ['l',                                  '١٤/\u200f٢/\u200f٢٠١٠'],
             ['ll',                                 '١٤ شباط فبراير ٢٠١٠'],
             ['lll',                                '١٤ شباط فبراير ٢٠١٠ ١٥:٢٥'],
             ['llll',                               'أحد ١٤ شباط فبراير ٢٠١٠ ١٥:٢٥']
@@ -322,3 +322,14 @@ test('strict ordinal parsing', function (assert) {
         assert.ok(testMoment.isValid(), 'strict ordinal parsing ' + i);
     }
 });
+
+test('no leading zeros in long date formats', function (assert) {
+    var i, j, longDateStr, shortDateStr;
+    for (i = 1; i <= 9; ++i) {
+        for (j = 1; j <= 9; ++j) {
+            longDateStr = moment([2014, i, j]).format('L');
+            shortDateStr = moment([2014, i, j]).format('l');
+            assert.equal(longDateStr, shortDateStr, 'should not have leading zeros in month or day');
+        }
+    }
+});