]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Parsing very early dates
authorTim Wood <washwithcare@gmail.com>
Wed, 25 Jul 2012 17:32:32 +0000 (10:32 -0700)
committerTim Wood <washwithcare@gmail.com>
Wed, 25 Jul 2012 17:32:32 +0000 (10:32 -0700)
#367

moment.js
test/moment/create.js

index 9dc35ad45639054645764126c63412101e8c5eeb..3c76a2a3a9529295fc23c3a3cd502c789804fdad 100644 (file)
--- a/moment.js
+++ b/moment.js
@@ -41,7 +41,7 @@
         parseTokenOneOrTwoDigits = /\d\d?/, // 0 - 99
         parseTokenOneToThreeDigits = /\d{1,3}/, // 0 - 999
         parseTokenThreeDigits = /\d{3}/, // 000 - 999
-        parseTokenFourDigits = /\d{4}/, // 0000 - 9999
+        parseTokenFourDigits = /\d{1,4}/, // 0 - 9999
         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 33d72f8531afff4ed924df44621f2f2337f08264..480386dca2fcc56540a3e41e21f36eaab01ae94e 100644 (file)
@@ -297,5 +297,23 @@ exports.create = {
         test.equal(moment(null), null, "Calling moment(null)");
         test.equal(moment('', 'YYYY-MM-DD'), null, "Calling moment('', 'YYYY-MM-DD')");
         test.done();
+    },
+
+    "first century" : function(test) {
+        test.expect(6);
+        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.done();
+    },
+
+    "six digit years" : function(test) {
+        test.expect(2);
+        test.equal(moment([-270000, 0, 1]).format("YYYY-MM-DD"), "-270000-01-01", "format BC 270,000");
+        test.equal(moment([ 270000, 0, 1]).format("YYYY-MM-DD"), "270000-01-01", "format AD 270,000");
+        test.done();
     }
 };