From d68fbdbb5b2db994d4b517c68798c14e1183df30 Mon Sep 17 00:00:00 2001 From: Tim Wood Date: Sat, 11 May 2013 19:39:36 +0200 Subject: [PATCH] adding isDST teste --- moment.js | 5 +++-- test/moment/zones.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/moment.js b/moment.js index 954091b48..267aba5ae 100644 --- a/moment.js +++ b/moment.js @@ -1270,8 +1270,8 @@ }, isDST : function () { - return (this.zone() < moment([this.year()]).zone() || - this.zone() < moment([this.year(), 5]).zone()); + return (this.zone() < this.clone().month(0).zone() || + this.zone() < this.clone().month(5).zone()); }, day : function (input) { @@ -1299,6 +1299,7 @@ } } this._d['set' + utc + 'Month'](input); + moment.updateOffset(this); return this; } else { return this._d['get' + utc + 'Month'](); diff --git a/test/moment/zones.js b/test/moment/zones.js index abf69126f..8adecbf58 100644 --- a/test/moment/zones.js +++ b/test/moment/zones.js @@ -366,6 +366,38 @@ exports.zones = { moment.updateOffset = oldOffset; + test.done(); + }, + + "isDST" : function (test) { + var oldOffset = moment.updateOffset; + + moment.updateOffset = function (mom) { + if (mom.month() > 2 && mom.month() < 9) { + mom.zone(-60); + } else { + mom.zone(0); + } + }; + + test.ok(!moment().month(0).isDST(), "Jan should not be summer dst"); + test.ok(moment().month(6).isDST(), "Jul should be summer dst"); + test.ok(!moment().month(11).isDST(), "Dec should not be summer dst"); + + moment.updateOffset = function (mom) { + if (mom.month() > 2 && mom.month() < 9) { + mom.zone(0); + } else { + mom.zone(-60); + } + }; + + test.ok(moment().month(0).isDST(), "Jan should be winter dst"); + test.ok(!moment().month(6).isDST(), "Jul should not be winter dst"); + test.ok(moment().month(11).isDST(), "Dec should be winter dst"); + + moment.updateOffset = oldOffset; + test.done(); } -- 2.47.2