]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
making auto iso8601 ignore 'T' if it is not in the input string #804
authorTim Wood <washwithcare@gmail.com>
Mon, 3 Jun 2013 17:52:32 +0000 (10:52 -0700)
committerTim Wood <washwithcare@gmail.com>
Mon, 3 Jun 2013 17:52:32 +0000 (10:52 -0700)
moment.js
test/moment/create.js

index 54b84c9e2d46a59a6b2a236de1efb3669b5630fa..51b92be0b2e88f5e291322ca04bc83aee895b0e0 100644 (file)
--- a/moment.js
+++ b/moment.js
     // date from iso format
     function makeDateFromString(config) {
         var i,
-            string = config._i;
-        if (isoRegex.exec(string)) {
-            config._f = 'YYYY-MM-DDT';
+            string = config._i,
+            match = isoRegex.exec(string);
+
+        if (match) {
+            // match[2] should be "T" or undefined
+            config._f = 'YYYY-MM-DD' + (match[2] || " ");
             for (i = 0; i < 4; i++) {
                 if (isoTimes[i][1].exec(string)) {
                     config._f += isoTimes[i][0];
index 9865002163a5f1cfc8a7e1eb4189e336ce53a3ff..c08536f36a224cd8bf81b097ca85fc0d6dfdeebe 100644 (file)
@@ -353,6 +353,24 @@ exports.create = {
         test.done();
     },
 
+    "parsing iso with T" : function(test) {
+        test.expect(9);
+
+        test.equal(moment('2011-10-08T18')._f, "YYYY-MM-DDTHH", "should include 'T' in the format");
+        test.equal(moment('2011-10-08T18:20')._f, "YYYY-MM-DDTHH:mm", "should include 'T' in the format");
+        test.equal(moment('2011-10-08T18:20:13')._f, "YYYY-MM-DDTHH:mm:ss", "should include 'T' in the format");
+        test.equal(moment('2011-10-08T18:20:13.321')._f, "YYYY-MM-DDTHH:mm:ss.S", "should include 'T' in the format");
+
+        test.equal(moment('2011-10-08 18')._f, "YYYY-MM-DD HH", "should not include 'T' in the format");
+        test.equal(moment('2011-10-08 18:20')._f, "YYYY-MM-DD HH:mm", "should not include 'T' in the format");
+        test.equal(moment('2011-10-08 18:20:13')._f, "YYYY-MM-DD HH:mm:ss", "should not include 'T' in the format");
+        test.equal(moment('2011-10-08 18:20:13.321')._f, "YYYY-MM-DD HH:mm:ss.S", "should not include 'T' in the format");
+
+        test.ok(moment("2013-04-23 15:23:47 UTC").isValid(), "including a trailing UTC in the input should work");
+
+        test.done();
+    },
+
     "parsing iso Z timezone" : function(test) {
         var i,
             formats = [