]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
zones outputting correct timestamped date with toDate
authorTim Wood <washwithcare@gmail.com>
Fri, 8 Mar 2013 04:34:06 +0000 (20:34 -0800)
committerTim Wood <washwithcare@gmail.com>
Fri, 8 Mar 2013 04:34:06 +0000 (20:34 -0800)
moment.js
test/moment/zones.js

index 9ed9f5c2242d604089c9b271d6d7460ab052383e..15b51e98d14340d019f636eb00a7bfefc5ac50fd 100644 (file)
--- a/moment.js
+++ b/moment.js
         },
 
         toDate : function () {
-            return this._d;
+            return this._offset ? new Date(+this) : this._d;
         },
 
         toJSON : function () {
index b32377eae91e162908c519984f672aac440cc49a..88876803d69dce7266eb084e1f41f685b9533076 100644 (file)
@@ -234,6 +234,19 @@ exports.zones = {
 
         test.equal(a.clone().local().hour(), 0, "calling moment#local should reset the offset");
 
+        test.done();
+    },
+
+    "toDate" : function (test) {
+        var zoneA = new Date(),
+            zoneB = moment(zoneA).zone(720).toDate(),
+            zoneC = moment(zoneA).zone(360).toDate(),
+            zoneD = moment(zoneA).zone(-690).toDate();
+
+        test.equal(+zoneA, +zoneB, "moment#toDate should output a date with the right unix timestamp");
+        test.equal(+zoneA, +zoneC, "moment#toDate should output a date with the right unix timestamp");
+        test.equal(+zoneA, +zoneD, "moment#toDate should output a date with the right unix timestamp");
+
         test.done();
     }