From: Maggie Pint Date: Mon, 5 Dec 2016 05:17:31 +0000 (-0800) Subject: fix conversion of parsed offset to hours X-Git-Tag: 2.18.0~43^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fee79115cf5a6258305676a8cd2a4d23f915b574;p=thirdparty%2Fmoment.git fix conversion of parsed offset to hours --- diff --git a/.gitignore b/.gitignore index 4d1faf41d..331e8f29d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ coverage nyc_output .nyc_output .coveralls.yml +.vscode/ \ No newline at end of file diff --git a/src/lib/units/offset.js b/src/lib/units/offset.js index 168aeadd8..752358f0d 100644 --- a/src/lib/units/offset.js +++ b/src/lib/units/offset.js @@ -102,7 +102,7 @@ hooks.updateOffset = function () {}; // a second time. In case it wants us to change the offset again // _changeInProgress == true case, then we have to adjust, because // there is no such time in the given timezone. -export function getSetOffset (input, keepLocalTime) { +export function getSetOffset (input, keepLocalTime, keepMinutes) { var offset = this._offset || 0, localAdjust; if (!this.isValid()) { @@ -114,7 +114,7 @@ export function getSetOffset (input, keepLocalTime) { if (input === null) { return this; } - } else if (Math.abs(input) < 16) { + } else if (Math.abs(input) < 16 && !keepMinutes) { input = input * 60; } if (!this._isUTC && keepLocalTime) { @@ -172,7 +172,7 @@ export function setOffsetToLocal (keepLocalTime) { export function setOffsetToParsedOffset () { if (this._tzm != null) { - this.utcOffset(this._tzm); + this.utcOffset(this._tzm, false, true); } else if (typeof this._i === 'string') { var tZone = offsetFromString(matchOffset, this._i); if (tZone != null) { diff --git a/src/test/moment/zones.js b/src/test/moment/zones.js index 785a1dbce..dbe9e2902 100644 --- a/src/test/moment/zones.js +++ b/src/test/moment/zones.js @@ -486,3 +486,16 @@ test('parse zone without a timezone', function (assert) { 'Not providing a timezone should keep the time and change the zone to 0' ); }); + +test('parse zone with a minutes unit abs less than 16 should retain minutes', function (assert) { + //ensure when minutes are explicitly parsed, they are retained + //instead of converted to hours, even if less than 16 + var n = moment.parseZone('2013-01-01T00:00:00-00:15'); + assert.equal(n.utcOffset(), -15); + assert.equal(n.zone(), 15); + assert.equal(n.hour(), 0); + var o = moment.parseZone('2013-01-01T00:00:00+00:15'); + assert.equal(o.utcOffset(), 15); + assert.equal(o.zone(), -15); + assert.equal(o.hour(), 0); +});