From: Mário Gonçalves Date: Fri, 5 Apr 2019 11:40:33 +0000 (+0100) Subject: Fix long date format inheritance interpolating characters inside square brackets X-Git-Tag: 2.25.0~66^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0666d68bbb0add8f53129a3673308805eeb143c2;p=thirdparty%2Fmoment.git Fix long date format inheritance interpolating characters inside square brackets --- diff --git a/src/lib/locale/formats.js b/src/lib/locale/formats.js index 6d83b0394..9f6a0e1dc 100644 --- a/src/lib/locale/formats.js +++ b/src/lib/locale/formats.js @@ -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]; } diff --git a/src/test/moment/locale_inheritance.js b/src/test/moment/locale_inheritance.js index 5a2ee0f21..36081a4e2 100644 --- a/src/test/moment/locale_inheritance.js +++ b/src/test/moment/locale_inheritance.js @@ -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) {