]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fix long date format inheritance interpolating characters inside square brackets
authorMário Gonçalves <mario.mc.goncalves@gmail.com>
Fri, 5 Apr 2019 11:40:33 +0000 (12:40 +0100)
committerIskren Chernev <iskren.chernev@gmail.com>
Fri, 24 Apr 2020 15:35:49 +0000 (18:35 +0300)
src/lib/locale/formats.js
src/test/moment/locale_inheritance.js

index 6d83b0394843d490250241143afd42937cce57f3..9f6a0e1dcd618cae699bbc8a17480780e5266cc6 100644 (file)
@@ -1,3 +1,5 @@
+import { formattingTokens } from '../format/format';
+
 export var defaultLongDateFormat = {
     LTS  : 'h:mm:ss A',
     LT   : 'h:mm A',
@@ -15,9 +17,12 @@ export function longDateFormat (key) {
         return format;
     }
 
-    this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) {
-        return val.slice(1);
-    });
+    this._longDateFormat[key] = formatUpper.match(formattingTokens).map(function (tok) {
+        if (tok === 'MMMM' || tok === 'MM' || tok === 'DD' || tok === 'dddd') {
+            return tok.slice(1);
+        }
+        return tok;
+    }).join('');
 
     return this._longDateFormat[key];
 }
index 5a2ee0f21b17a71498b39d943af0c69d75c87c80..36081a4e2cb39a99bee32a6594ce0f62b9cae148 100644 (file)
@@ -76,8 +76,8 @@ test('long date format', function (assert) {
     moment.defineLocale('child-ldf', {
         parentLocale: 'base-ldf',
         longDateFormat: {
-            LLL  : '[child] MMMM D, YYYY h:mm A',
-            LLLL : '[child] dddd, MMMM D, YYYY h:mm A'
+            LLL  : '[SUMMER child] MMMM D, YYYY h:mm A',
+            LLLL : '[SUMMER child] dddd, MMMM D, YYYY h:mm A'
         }
     });
 
@@ -89,10 +89,10 @@ test('long date format', function (assert) {
     assert.equal(anchor.format('l'), '9/6/2015', 'l uses base');
     assert.equal(anchor.format('LL'), 'September 6, 2015', 'LL uses base');
     assert.equal(anchor.format('ll'), 'Sep 6, 2015', 'll uses base');
-    assert.equal(anchor.format('LLL'), 'child September 6, 2015 12:34 PM', 'LLL uses child');
-    assert.equal(anchor.format('lll'), 'child Sep 6, 2015 12:34 PM', 'lll uses child');
-    assert.equal(anchor.format('LLLL'), 'child Sunday, September 6, 2015 12:34 PM', 'LLLL uses child');
-    assert.equal(anchor.format('llll'), 'child Sun, Sep 6, 2015 12:34 PM', 'llll uses child');
+    assert.equal(anchor.format('LLL'), 'SUMMER child September 6, 2015 12:34 PM', 'LLL uses child');
+    assert.equal(anchor.format('lll'), 'SUMMER child Sep 6, 2015 12:34 PM', 'lll uses child');
+    assert.equal(anchor.format('LLLL'), 'SUMMER child Sunday, September 6, 2015 12:34 PM', 'LLLL uses child');
+    assert.equal(anchor.format('llll'), 'SUMMER child Sun, Sep 6, 2015 12:34 PM', 'llll uses child');
 });
 
 test('ordinal', function (assert) {