From: Isaac Cambron Date: Fri, 23 Aug 2013 00:15:38 +0000 (-0400) Subject: name change and a some more thoroughness X-Git-Tag: 2.2.0~11^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b719260e9dcd7c60f58dd742ca104415284ac7d2;p=thirdparty%2Fmoment.git name change and a some more thoroughness --- diff --git a/moment.js b/moment.js index 176d48d79..578dcfcf6 100644 --- a/moment.js +++ b/moment.js @@ -1477,12 +1477,15 @@ return this._isUTC ? "Coordinated Universal Time" : ""; }, - hasAlignedHours : function (input) { + hasAlignedHourOffset : function (input) { + var mod = this.zone() % 60, + wrapAround = function (minutes) {return minutes < 0 ? 60 + minutes : minutes; }; + if (input == null || input === '') { - return this.zone() % 60 === 0; + return mod === 0; } else { - return this.zone() % 60 === moment(input).zone() % 60; + return wrapAround(mod) === wrapAround(moment(input).zone() % 60); } }, diff --git a/test/moment/zones.js b/test/moment/zones.js index 9c3cecac1..46a22dc85 100644 --- a/test/moment/zones.js +++ b/test/moment/zones.js @@ -420,23 +420,45 @@ exports.zones = { "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.equals(moment().zone(120).hasAlignedHourOffset(), true); + test.equals(moment().zone(-180).hasAlignedHourOffset(), true); + test.equals(moment().zone(90).hasAlignedHourOffset(), false); + test.equals(moment().zone(-90).hasAlignedHourOffset(), false); test.done(); }, "hours alignment with other zone" : function (test) { - test.expect(4); + test.expect(16); 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.equals(m.hasAlignedHourOffset(moment().zone(180)), true); + test.equals(m.hasAlignedHourOffset(moment().zone(-180)), true); + test.equals(m.hasAlignedHourOffset(moment().zone(90)), false); + test.equals(m.hasAlignedHourOffset(moment().zone(-90)), false); + + m = moment().zone(90); + + test.equals(m.hasAlignedHourOffset(moment().zone(180)), false); + test.equals(m.hasAlignedHourOffset(moment().zone(-180)), false); + test.equals(m.hasAlignedHourOffset(moment().zone(30)), true); + test.equals(m.hasAlignedHourOffset(moment().zone(-30)), true); + + m = moment().zone(-60); + + test.equals(m.hasAlignedHourOffset(moment().zone(180)), true); + test.equals(m.hasAlignedHourOffset(moment().zone(-180)), true); + test.equals(m.hasAlignedHourOffset(moment().zone(90)), false); + test.equals(m.hasAlignedHourOffset(moment().zone(-90)), false); + + m = moment().zone(25); + + test.equals(m.hasAlignedHourOffset(moment().zone(-35)), true); + test.equals(m.hasAlignedHourOffset(moment().zone(85)), true); + + test.equals(m.hasAlignedHourOffset(moment().zone(35)), false); + test.equals(m.hasAlignedHourOffset(moment().zone(-85)), false); test.done(); }