]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
added isDST method to moment.fn 81/head
authorRocky Meza <rockymeza@gmail.com>
Tue, 29 Nov 2011 05:23:31 +0000 (22:23 -0700)
committerRocky Meza <rockymeza@gmail.com>
Tue, 29 Nov 2011 05:23:31 +0000 (22:23 -0700)
moment.js
sitesrc/js/unit-tests.js

index 9565ed16bb938c9a2c8fa68a86c20772191d52c1..a64cc5ebb8579eb8e192e0d5807d7a76f792966c 100644 (file)
--- a/moment.js
+++ b/moment.js
         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();
         }
     };
 
index cde923216d4af21d879210e85c118fa5067894c4..29928bf6f8317344d513ba04d4ed9a50c0782c0e 100755 (executable)
@@ -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');
+});
+
 })();