// 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
// 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);
}
},
"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');
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();
},