]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
added hasAlignedHours
authorIsaac Cambron <icambron@gmail.com>
Mon, 19 Aug 2013 06:42:09 +0000 (02:42 -0400)
committerIsaac Cambron <icambron@gmail.com>
Fri, 23 Aug 2013 00:25:19 +0000 (20:25 -0400)
moment.js
test/moment/zones.js

index 03d66a4e02e82602d7467ffd5ca388f0e6ed97ea..176d48d79654eba3c399300d438b247074b06bc7 100644 (file)
--- a/moment.js
+++ b/moment.js
             return this._isUTC ? "Coordinated Universal Time" : "";
         },
 
+        hasAlignedHours : function (input) {
+            if (input == null || input === '') {
+                return this.zone() % 60 === 0;
+            }
+            else {
+                return this.zone() % 60 === moment(input).zone() % 60;
+            }
+        },
+
         daysInMonth : function () {
             return moment.utc([this.year(), this.month() + 1, 0]).date();
         },
index f6b2f3d101430f837ca9754783f88c410819167e..9c3cecac10525e8ace9b7b2128fc45c720c1abf1 100644 (file)
@@ -415,6 +415,29 @@ exports.zones = {
         test.equal(moment.utc().format('zz'), "Coordinated Universal Time", "UTC zone formatted abbr should be Coordinated Universal Time");
 
         test.done();
-    }
+    },
+
+    "hours alignment with UTC" : function (test) {
+        test.expect(4);
+
+        test.equals(moment().zone(120).hasAlignedHours(), true);
+        test.equals(moment().zone(-180).hasAlignedHours(), true);
+        test.equals(moment().zone(90).hasAlignedHours(), false);
+        test.equals(moment().zone(-90).hasAlignedHours(), false);
+
+        test.done();
+    },
+
+    "hours alignment with other zone" : function (test) {
+        test.expect(4);
+
+        var m = moment().zone(120);
 
+        test.equals(m.hasAlignedHours(moment().zone(180)), true);
+        test.equals(m.hasAlignedHours(moment().zone(-180)), true);
+        test.equals(m.hasAlignedHours(moment().zone(90)), false);
+        test.equals(m.hasAlignedHours(moment().zone(-90)), false);
+
+        test.done();
+    }
 };