From: Tim Wood Date: Fri, 8 Mar 2013 04:34:06 +0000 (-0800) Subject: zones outputting correct timestamped date with toDate X-Git-Tag: 2.1.0~32^2~2^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb5146f37f645fa74973454803e64ad95d5d2a29;p=thirdparty%2Fmoment.git zones outputting correct timestamped date with toDate --- diff --git a/moment.js b/moment.js index 9ed9f5c22..15b51e98d 100644 --- a/moment.js +++ b/moment.js @@ -1063,7 +1063,7 @@ }, toDate : function () { - return this._d; + return this._offset ? new Date(+this) : this._d; }, toJSON : function () { diff --git a/test/moment/zones.js b/test/moment/zones.js index b32377eae..88876803d 100644 --- a/test/moment/zones.js +++ b/test/moment/zones.js @@ -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(); }