From: Isaac Cambron Date: Mon, 19 Aug 2013 06:42:09 +0000 (-0400) Subject: added hasAlignedHours X-Git-Tag: 2.2.0~11^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73745a1c7ecc3169ad3e6c478f0c2d253b6eb7db;p=thirdparty%2Fmoment.git added hasAlignedHours --- diff --git a/moment.js b/moment.js index 03d66a4e0..176d48d79 100644 --- a/moment.js +++ b/moment.js @@ -1477,6 +1477,15 @@ 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(); }, diff --git a/test/moment/zones.js b/test/moment/zones.js index f6b2f3d10..9c3cecac1 100644 --- a/test/moment/zones.js +++ b/test/moment/zones.js @@ -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(); + } };