From: Rocky Meza Date: Tue, 29 Nov 2011 05:23:31 +0000 (-0700) Subject: added isDST method to moment.fn X-Git-Tag: 1.2.0~27^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F81%2Fhead;p=thirdparty%2Fmoment.git added isDST method to moment.fn --- 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'); +}); + })();