]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fixing bug where moment.utc(isostringwithoutzone) does not parse as utc
authorTim Wood <washwithcare@gmail.com>
Wed, 25 Apr 2012 00:17:27 +0000 (17:17 -0700)
committerTim Wood <washwithcare@gmail.com>
Wed, 25 Apr 2012 00:17:27 +0000 (17:17 -0700)
#275

moment.js
test/moment/utc.js

index 794f48052044eb7feabac12169df00d148178a9d..06a15639d312d2a32d95eb42203256b4217cfb7b 100644 (file)
--- a/moment.js
+++ b/moment.js
         if (isArray(input)) {
             return new Moment(new Date(Date.UTC.apply({}, input)), true);
         }
-        return (format && input) ? moment(input + ' +00:00', format + ' Z').utc() : moment(input).utc();
+        return (format && input) ?
+            moment(input + ' +0000', format + ' Z').utc() :
+            moment(parseTokenTimezone.exec(input) ? input : input + '+0000').utc();
     };
 
     // creating with unix timestamp (in seconds)
index 1a0507e735be6dbf28e18d90c33f3be2fb3cf4f0..866bd54723651eaf86aa4485b58c6e129f023e69 100644 (file)
@@ -42,6 +42,20 @@ exports.utc = {
         test.equal(m.date(), 2, "the day should be correct for utc parsing iso");
         test.equal(m.hours(), 3, "the hours should be correct for utc parsing iso");
 
+        test.done();
+    },
+
+    "creating with utc without timezone" : function(test) {
+        test.expect(4);
+
+        var m = moment.utc("2012-01-02T08:20:00");
+        test.equal(m.date(), 2, "the day should be correct for utc parse without timezone");
+        test.equal(m.hours(), 8, "the hours should be correct for utc parse without timezone");
+
+        m = moment.utc("2012-01-02T08:20:00+09:00");
+        test.equal(m.date(), 1, "the day should be correct for utc parse with timezone");
+        test.equal(m.hours(), 23, "the hours should be correct for utc parse with timezone");
+
         test.done();
     }
 };