From c45c7cba6aa7a771268507c9465b5bb7b13544a3 Mon Sep 17 00:00:00 2001 From: Rocky Meza Date: Mon, 28 Nov 2011 22:23:31 -0700 Subject: [PATCH] added isDST method to moment.fn --- moment.js | 5 +++++ sitesrc/js/unit-tests.js | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/moment.js b/moment.js index 9565ed16b..a64cc5ebb 100644 --- a/moment.js +++ b/moment.js @@ -486,6 +486,11 @@ isLeapYear : function () { var year = this._d.getFullYear(); return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0; + }, + + isDST : function() { + var dayOne = new Date(this._d.getFullYear(), 0, 1, 0, 0, 0); + return this._d.getTimezoneOffset() !== dayOne.getTimezoneOffset(); } }; diff --git a/sitesrc/js/unit-tests.js b/sitesrc/js/unit-tests.js index cde923216..29928bf6f 100755 --- a/sitesrc/js/unit-tests.js +++ b/sitesrc/js/unit-tests.js @@ -322,5 +322,13 @@ test("format timezone", 2, function() { ok(b.format('zz').match(/^[A-Z]{3,5}$/), b.format('zz') + ' ---> Something like "PST"'); }); +test("isDST", 2, function() { + // In the US 2011 March 13 is Daylight Savings Day + var a = moment(new Date(2011, 2, 12, 0, 0, 0)), + b = moment(new Date(2011, 2, 14, 0, 0, 0)); + ok(!a.isDST(), '2011 March 12 is not DST'); + ok(b.isDST(), '2011 March 14 is DST'); +}); + })(); -- 2.47.2