From: Jason Davies Date: Wed, 25 Jul 2012 18:10:05 +0000 (+0100) Subject: Relax year digits required. X-Git-Tag: 2.0.0~83^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F373%2Fhead;p=thirdparty%2Fmoment.git Relax year digits required. This restores the ability to parse 1 Dec 1. --- diff --git a/moment.js b/moment.js index 39711eba2..0d3f49c26 100644 --- a/moment.js +++ b/moment.js @@ -41,8 +41,8 @@ parseTokenOneOrTwoDigits = /\d\d?/, // 0 - 99 parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999 parseTokenThreeDigits = /\d{3}/, // 000 - 999 - parseTokenFourDigits = /\d{4}/, // 0000 - 9999 - parseTokenFiveToSixDigits = /[+\-\d]?\d{4,6}/, // -999,999 - 999,999 + parseTokenFourDigits = /\d{1,4}/, // 0 - 9999 + parseTokenSixDigits = /[+\-]?\d{1,6}/, // -999,999 - 999,999 parseTokenWord = /[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/i, // any word characters or numbers parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/i, // +00:00 -00:00 +0000 -0000 or Z parseTokenT = /T/i, // T (ISO seperator) @@ -405,7 +405,7 @@ case 'YYYY': return parseTokenFourDigits; case 'YYYYY': - return parseTokenFiveToSixDigits; + return parseTokenSixDigits; case 'S': case 'SS': case 'SSS': diff --git a/test/moment/create.js b/test/moment/create.js index 815b933da..59a6f2130 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -300,10 +300,16 @@ exports.create = { }, "first century" : function(test) { - test.expect(3); + test.expect(9); test.equal(moment([0, 0, 1]).format("YYYY-MM-DD"), "0000-01-01", "Year AD 0"); test.equal(moment([99, 0, 1]).format("YYYY-MM-DD"), "0099-01-01", "Year AD 99"); test.equal(moment([999, 0, 1]).format("YYYY-MM-DD"), "0999-01-01", "Year AD 999"); + test.equal(moment('0 1 1', 'YYYY MM DD').format("YYYY-MM-DD"), "0000-01-01", "Year AD 0"); + test.equal(moment('99 1 1', 'YYYY MM DD').format("YYYY-MM-DD"), "0099-01-01", "Year AD 99"); + test.equal(moment('999 1 1', 'YYYY MM DD').format("YYYY-MM-DD"), "0999-01-01", "Year AD 999"); + test.equal(moment('0 1 1', 'YYYYY MM DD').format("YYYYY-MM-DD"), "00000-01-01", "Year AD 0"); + test.equal(moment('99 1 1', 'YYYYY MM DD').format("YYYYY-MM-DD"), "00099-01-01", "Year AD 99"); + test.equal(moment('999 1 1', 'YYYYY MM DD').format("YYYYY-MM-DD"), "00999-01-01", "Year AD 999"); test.done(); },