]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fixing #380
authorTim Wood <washwithcare@gmail.com>
Fri, 3 Aug 2012 16:13:59 +0000 (09:13 -0700)
committerTim Wood <washwithcare@gmail.com>
Fri, 3 Aug 2012 16:13:59 +0000 (09:13 -0700)
moment.js
test/moment/format.js

index 95520c0dd3dabd9533938fc281eb62db1e37e718..f0554ad1eb646cc24cb3e6871c2e21aff5349b5d 100644 (file)
--- 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
 
     // 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);
         }
 
index 3fe3f745ea09a36d33f117b3ac03034145b543c4..9681a2b8626fd9c9071869c1c66415f40a299ede 100644 (file)
@@ -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();
     },