]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Add support for negative four-digit years. 367/head
authorJason Davies <jason@jasondavies.com>
Thu, 19 Jul 2012 14:43:25 +0000 (15:43 +0100)
committerJason Davies <jason@jasondavies.com>
Thu, 19 Jul 2012 14:43:25 +0000 (15:43 +0100)
moment.js
test/moment/create.js

index f430bc781ccca75969306e9948356558c5a5f667..ef1cf28ddf9513021cdc14373775870046fb37d9 100644 (file)
--- a/moment.js
+++ b/moment.js
@@ -42,7 +42,7 @@
         parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999
         parseTokenThreeDigits = /\d{3}/, // 000 - 999
         parseTokenFourDigits = /\d{4}/, // 0000 - 9999
-        parseTokenFiveToSixDigits = /[+\-]?\d{5,6}/, // -999,999 - 999,999
+        parseTokenFiveToSixDigits = /[+\-\d]?\d{4,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)
index 52befca237fea61e966ee1686052d1462c875760..4658f7b4595e3bb837cf5036d85c7bba3569aa02 100644 (file)
@@ -305,11 +305,17 @@ exports.create = {
 
     "six digit years" : function(test) {
         test.expect(5);
-        test.equal(moment([-270000, 0, 1]).format("YYYYY-MM-DD"), "-270000-01-01", "format BC 270,000");
+        test.equal(moment([-270000, 0, 1]).format("YYYYY-MM-DD"), "-270000-01-01", "format BC 270,001");
         test.equal(moment([ 270000, 0, 1]).format("YYYYY-MM-DD"), "270000-01-01", "format AD 270,000");
-        test.equal(moment("-270000-01-01", "YYYYY-MM-DD").toDate().getUTCFullYear(), -270000, "parse BC 270,000");
+        test.equal(moment("-270000-01-01", "YYYYY-MM-DD").toDate().getUTCFullYear(), -270000, "parse BC 270,001");
         test.equal(moment("270000-01-01",  "YYYYY-MM-DD").toDate().getUTCFullYear(), 270000, "parse AD 270,000");
         test.equal(moment("+270000-01-01", "YYYYY-MM-DD").toDate().getUTCFullYear(), 270000, "parse AD +270,000");
         test.done();
+    },
+
+    "negative four digit years" : function(test) {
+        test.expect(1);
+        test.equal(moment("-1000-01-01", "YYYYY-MM-DD").toDate().getUTCFullYear(), -1000, "parse BC 1,001");
+        test.done();
     }
 };