From 2540ea08cd2ca6348da4347695b33c81dc6f4da2 Mon Sep 17 00:00:00 2001 From: ssskip Date: Thu, 13 Oct 2016 15:16:05 +0800 Subject: [PATCH] fix #397 zone.offset has been deprecated in favor of zone.utcOffset --- moment-timezone.js | 9 +++++++-- tests/helpers/helpers.js | 2 +- tests/moment-timezone/guess.js | 2 +- tests/moment-timezone/zone.js | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/moment-timezone.js b/moment-timezone.js index a61148d0..4638e174 100644 --- a/moment-timezone.js +++ b/moment-timezone.js @@ -192,6 +192,11 @@ }, offset : function (mom) { + logError("zone.offset has been deprecated in favor of zone.utcOffset"); + return this.offsets[this._index(mom)]; + }, + + utcOffset : function (mom) { return this.offsets[this._index(mom)]; } }; @@ -231,7 +236,7 @@ } ZoneScore.prototype.scoreOffsetAt = function (offsetAt) { - this.offsetScore += Math.abs(this.zone.offset(offsetAt.at) - offsetAt.offset); + this.offsetScore += Math.abs(this.zone.utcOffset(offsetAt.at) - offsetAt.offset); if (this.zone.abbr(offsetAt.at).replace(/[^A-Z]/g, '') !== offsetAt.abbr) { this.abbrScore++; } @@ -533,7 +538,7 @@ mom._z = zone; } if (mom._z) { - offset = mom._z.offset(mom); + offset = mom._z.utcOffset(mom); if (Math.abs(offset) < 16) { offset = offset / 60; } diff --git a/tests/helpers/helpers.js b/tests/helpers/helpers.js index 0a88dfc1..7e9ff8c7 100644 --- a/tests/helpers/helpers.js +++ b/tests/helpers/helpers.js @@ -38,7 +38,7 @@ function testYear(test, name, expected) { function mockTimezoneOffset(name) { var zone = moment.tz.zone(name); Date.prototype.getTimezoneOffset = function () { - return zone.offset(+this); + return zone.utcOffset(+this); }; } diff --git a/tests/moment-timezone/guess.js b/tests/moment-timezone/guess.js index 0e52ed47..7bc02761 100644 --- a/tests/moment-timezone/guess.js +++ b/tests/moment-timezone/guess.js @@ -9,7 +9,7 @@ var oldIntl = parent.Intl; function mockTimezoneOffset (zone, format) { Date.prototype.getTimezoneOffset = function () { - return zone.offset(+this); + return zone.utcOffset(+this); }; Date.prototype.toTimeString = function () { return tz(+this, zone.name).format(format || 'HH:mm:ss [GMT]ZZ'); diff --git a/tests/moment-timezone/zone.js b/tests/moment-timezone/zone.js index 8dac8c14..ad4953b5 100644 --- a/tests/moment-timezone/zone.js +++ b/tests/moment-timezone/zone.js @@ -84,7 +84,7 @@ exports.zone = { for (i = 0; i < tests.length; i++) { source = tests[i][0]; expected = tests[i][1]; - test.equal(zone.offset(source), expected, "The offset for " + source + " should be " + expected); + test.equal(zone.utcOffset(source), expected, "The offset for " + source + " should be " + expected); } test.done();