From: Tim Wood Date: Fri, 3 Aug 2012 16:13:59 +0000 (-0700) Subject: Fixing #380 X-Git-Tag: 1.7.1~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97904f1153d680f7770b2564da44b8ec5e996e9c;p=thirdparty%2Fmoment.git Fixing #380 --- diff --git a/moment.js b/moment.js index 95520c0dd..f0554ad1e 100644 --- a/moment.js +++ b/moment.js @@ -31,7 +31,7 @@ // format tokens formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|zz?|ZZ?)/g, - localFormattingTokens = /(LT|LL?L?L?)/g, + localFormattingTokens = /(\[[^\[]*\])|(\\)?(LT|LL?L?L?)/g, formattingRemoveEscapes = /(^\[)|(\\)|\]$/g, // parsing tokens @@ -372,13 +372,13 @@ // format date using native date object function formatMoment(m, format) { - var lang = getLangDefinition(m); + var lang = getLangDefinition(m), i = 2; function getValueFromArray(key, index) { return lang[key].call ? lang[key](m, format) : lang[key][index]; } - while (localFormattingTokens.test(format)) { + while (i--) { format = format.replace(localFormattingTokens, replaceLongDateFormatTokens); } diff --git a/test/moment/format.js b/test/moment/format.js index 3fe3f745e..9681a2b86 100644 --- a/test/moment/format.js +++ b/test/moment/format.js @@ -10,7 +10,7 @@ exports.format = { }, "format escape brackets" : function(test) { - test.expect(7); + test.expect(9); var b = moment(new Date(2009, 1, 14, 15, 25, 50, 125)); test.equal(b.format('[day]'), 'day', 'Single bracket'); @@ -20,6 +20,8 @@ exports.format = { test.equal(b.format('[[]'), '[', 'Escape open bracket'); test.equal(b.format('[Last]'), 'Last', 'localized tokens'); test.equal(b.format('[L] L'), 'L 02/14/2009', 'localized tokens with escaped localized tokens'); + test.equal(b.format('[L LL LLL LLLL aLa]'), 'L LL LLL LLLL aLa', 'localized tokens with escaped localized tokens'); + test.equal(b.format('[LLL] LLL'), 'LLL February 14 2009 3:25 PM', 'localized tokens with escaped localized tokens (recursion)'); test.done(); },