]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
fix conversion of parsed offset to hours
authorMaggie Pint <magpint@microsoft.com>
Mon, 5 Dec 2016 05:17:31 +0000 (21:17 -0800)
committerIskren Chernev <iskren.chernev@gmail.com>
Thu, 2 Mar 2017 08:53:24 +0000 (10:53 +0200)
.gitignore
src/lib/units/offset.js
src/test/moment/zones.js

index 4d1faf41dc732555f14d231885ecb6db4ba321c0..331e8f29d077bb731a01ad755e0358aaebfe59e7 100644 (file)
@@ -11,3 +11,4 @@ coverage
 nyc_output
 .nyc_output
 .coveralls.yml
+.vscode/
\ No newline at end of file
index 168aeadd808610444d6d4aa1437fd40aa9252ec0..752358f0d8c367b3bfebe1e7acca003f733402be 100644 (file)
@@ -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) {
index 785a1dbce6fb6ba8c276dd7719d6403f0577821d..dbe9e2902c11d706315500c3ad4c014471ea0ca9 100644 (file)
@@ -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);
+});