From 407b3d77ba3bc0c5694beb9c1ff27384f3f6bcb2 Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Mon, 1 Dec 2014 01:43:34 -0800 Subject: [PATCH 1/2] Prefer moment.fn.utcOffset to moment.fn.zone --- moment-timezone.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/moment-timezone.js b/moment-timezone.js index 870e1eb8..2e0bb592 100644 --- a/moment-timezone.js +++ b/moment-timezone.js @@ -349,7 +349,11 @@ if (Math.abs(offset) < 16) { offset = offset / 60; } - mom.zone(offset, keepTime); + if (mom.utcOffset !== undefined) { + mom.utcOffset(-offset, keepTime); + } else { + mom.zone(offset, keepTime); + } } }; From d2d236fa8505f44d9681ffc461c70d67d62d1d02 Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Mon, 1 Dec 2014 01:58:20 -0800 Subject: [PATCH 2/2] Update tests to use utcOffset instead of zone --- tests/helpers/helpers.js | 4 +-- tests/moment-timezone/parse.js | 64 +++++++++++++++++----------------- tests/moment-timezone/utc.js | 12 +++---- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/tests/helpers/helpers.js b/tests/helpers/helpers.js index f1690c9f..a06b2e55 100644 --- a/tests/helpers/helpers.js +++ b/tests/helpers/helpers.js @@ -16,7 +16,7 @@ function testYear(test, name, expected) { offset = expected[i][3]; m = moment(date).tz(name); test.equal(m.format("HH:mm:ss"), time, date + ' should be ' + time + ' ' + abbr); - test.equal(m.zone(), offset, date + ' should be ' + offset + ' minutes offset in ' + abbr); + test.equal(m.utcOffset(), -offset, date + ' should be ' + offset + ' minutes offset in ' + abbr); test.equal(m.zoneAbbr(), abbr, date + ' should be ' + abbr); } @@ -29,4 +29,4 @@ module.exports = { testYear(test, name, expected); }; } -}; \ No newline at end of file +}; diff --git a/tests/moment-timezone/parse.js b/tests/moment-timezone/parse.js index babd4e35..340a88f7 100644 --- a/tests/moment-timezone/parse.js +++ b/tests/moment-timezone/parse.js @@ -43,10 +43,10 @@ exports.parse = { t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -08:00", "During the lost hour, the time should roll back to the previous time"); t.equal( after.format("HH mm ss Z"), "03 00 00 -07:00", "After the lost hour, the time should match the input time"); - t.equal( before.zone(), 480, "Before the lost hour, the offset should match the non-dst offset"); - t.equal(atStart.zone(), 480, "During the lost hour, the offset should match the non-dst offset"); - t.equal( atEnd.zone(), 480, "During the lost hour, the offset should match the non-dst offset"); - t.equal( after.zone(), 420, "After the lost hour, the offset should match the dst offset"); + t.equal( before.utcOffset(), -480, "Before the lost hour, the offset should match the non-dst offset"); + t.equal(atStart.utcOffset(), -480, "During the lost hour, the offset should match the non-dst offset"); + t.equal( atEnd.utcOffset(), -480, "During the lost hour, the offset should match the non-dst offset"); + t.equal( after.utcOffset(), -420, "After the lost hour, the offset should match the dst offset"); t.done(); }, @@ -65,10 +65,10 @@ exports.parse = { t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -05:00", "During the lost hour, the time should roll back to the previous time"); t.equal( after.format("HH mm ss Z"), "03 00 00 -04:00", "After the lost hour, the time should match the input time"); - t.equal( before.zone(), 300, "Before the lost hour, the offset should match the non-dst offset"); - t.equal(atStart.zone(), 300, "During the lost hour, the offset should match the non-dst offset"); - t.equal( atEnd.zone(), 300, "During the lost hour, the offset should match the non-dst offset"); - t.equal( after.zone(), 240, "After the lost hour, the offset should match the dst offset"); + t.equal( before.utcOffset(), -300, "Before the lost hour, the offset should match the non-dst offset"); + t.equal(atStart.utcOffset(), -300, "During the lost hour, the offset should match the non-dst offset"); + t.equal( atEnd.utcOffset(), -300, "During the lost hour, the offset should match the non-dst offset"); + t.equal( after.utcOffset(), -240, "After the lost hour, the offset should match the dst offset"); t.done(); }, @@ -87,10 +87,10 @@ exports.parse = { t.equal( atEnd.format("HH mm ss Z"), "03 59 59 -07:00", "During the lost hour, the time should roll forward to the previous time"); t.equal( after.format("HH mm ss Z"), "03 00 00 -07:00", "After the lost hour, the time should match the input time"); - t.equal( before.zone(), 480, "Before the lost hour, the offset should match the non-dst offset"); - t.equal(atStart.zone(), 420, "During the lost hour, the offset should match the dst offset"); - t.equal( atEnd.zone(), 420, "During the lost hour, the offset should match the dst offset"); - t.equal( after.zone(), 420, "After the lost hour, the offset should match the dst offset"); + t.equal( before.utcOffset(), -480, "Before the lost hour, the offset should match the non-dst offset"); + t.equal(atStart.utcOffset(), -420, "During the lost hour, the offset should match the dst offset"); + t.equal( atEnd.utcOffset(), -420, "During the lost hour, the offset should match the dst offset"); + t.equal( after.utcOffset(), -420, "After the lost hour, the offset should match the dst offset"); t.done(); }, @@ -109,10 +109,10 @@ exports.parse = { t.equal( atEnd.format("HH mm ss Z"), "03 59 59 -04:00", "During the lost hour, the time should roll forward to the previous time"); t.equal( after.format("HH mm ss Z"), "03 00 00 -04:00", "After the lost hour, the time should match the input time"); - t.equal( before.zone(), 300, "Before the lost hour, the offset should match the non-dst offset"); - t.equal(atStart.zone(), 240, "During the lost hour, the offset should match the dst offset"); - t.equal( atEnd.zone(), 240, "During the lost hour, the offset should match the dst offset"); - t.equal( after.zone(), 240, "After the lost hour, the offset should match the dst offset"); + t.equal( before.utcOffset(), -300, "Before the lost hour, the offset should match the non-dst offset"); + t.equal(atStart.utcOffset(), -240, "During the lost hour, the offset should match the dst offset"); + t.equal( atEnd.utcOffset(), -240, "During the lost hour, the offset should match the dst offset"); + t.equal( after.utcOffset(), -240, "After the lost hour, the offset should match the dst offset"); t.done(); }, @@ -131,10 +131,10 @@ exports.parse = { t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -07:00", "During the duplicated hour, the time should match the earlier input time"); t.equal( after.format("HH mm ss Z"), "02 00 00 -08:00", "After the duplicated hour, the time should match the input time"); - t.equal( before.zone(), 420, "Before the duplicated hour, the offset should match the dst offset"); - t.equal(atStart.zone(), 420, "During the duplicated hour, the offset should match the dst offset"); - t.equal( atEnd.zone(), 420, "During the duplicated hour, the offset should match the dst offset"); - t.equal( after.zone(), 480, "After the duplicated hour, the offset should match the non-dst offset"); + t.equal( before.utcOffset(), -420, "Before the duplicated hour, the offset should match the dst offset"); + t.equal(atStart.utcOffset(), -420, "During the duplicated hour, the offset should match the dst offset"); + t.equal( atEnd.utcOffset(), -420, "During the duplicated hour, the offset should match the dst offset"); + t.equal( after.utcOffset(), -480, "After the duplicated hour, the offset should match the non-dst offset"); t.done(); }, @@ -153,10 +153,10 @@ exports.parse = { t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -04:00", "During the duplicated hour, the time should match the earlier input time"); t.equal( after.format("HH mm ss Z"), "02 00 00 -05:00", "After the duplicated hour, the time should match the input time"); - t.equal( before.zone(), 240, "Before the duplicated hour, the offset should match the dst offset"); - t.equal(atStart.zone(), 240, "During the duplicated hour, the offset should match the dst offset"); - t.equal( atEnd.zone(), 240, "During the duplicated hour, the offset should match the dst offset"); - t.equal( after.zone(), 300, "After the duplicated hour, the offset should match the non-dst offset"); + t.equal( before.utcOffset(), -240, "Before the duplicated hour, the offset should match the dst offset"); + t.equal(atStart.utcOffset(), -240, "During the duplicated hour, the offset should match the dst offset"); + t.equal( atEnd.utcOffset(), -240, "During the duplicated hour, the offset should match the dst offset"); + t.equal( after.utcOffset(), -300, "After the duplicated hour, the offset should match the non-dst offset"); t.done(); }, @@ -175,10 +175,10 @@ exports.parse = { t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -08:00", "During the duplicated hour, the time should match the later input time"); t.equal( after.format("HH mm ss Z"), "02 00 00 -08:00", "After the duplicated hour, the time should match the input time"); - t.equal( before.zone(), 420, "Before the duplicated hour, the offset should match the dst offset"); - t.equal(atStart.zone(), 480, "During the duplicated hour, the offset should match the non-dst offset"); - t.equal( atEnd.zone(), 480, "During the duplicated hour, the offset should match the non-dst offset"); - t.equal( after.zone(), 480, "After the duplicated hour, the offset should match the non-dst offset"); + t.equal( before.utcOffset(), -420, "Before the duplicated hour, the offset should match the dst offset"); + t.equal(atStart.utcOffset(), -480, "During the duplicated hour, the offset should match the non-dst offset"); + t.equal( atEnd.utcOffset(), -480, "During the duplicated hour, the offset should match the non-dst offset"); + t.equal( after.utcOffset(), -480, "After the duplicated hour, the offset should match the non-dst offset"); t.done(); }, @@ -197,10 +197,10 @@ exports.parse = { t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -05:00", "During the duplicated hour, the time should match the later input time"); t.equal( after.format("HH mm ss Z"), "02 00 00 -05:00", "After the duplicated hour, the time should match the input time"); - t.equal( before.zone(), 240, "Before the duplicated hour, the offset should match the dst offset"); - t.equal(atStart.zone(), 300, "During the duplicated hour, the offset should match the non-dst offset"); - t.equal( atEnd.zone(), 300, "During the duplicated hour, the offset should match the non-dst offset"); - t.equal( after.zone(), 300, "After the duplicated hour, the offset should match the non-dst offset"); + t.equal( before.utcOffset(), -240, "Before the duplicated hour, the offset should match the dst offset"); + t.equal(atStart.utcOffset(), -300, "During the duplicated hour, the offset should match the non-dst offset"); + t.equal( atEnd.utcOffset(), -300, "During the duplicated hour, the offset should match the non-dst offset"); + t.equal( after.utcOffset(), -300, "After the duplicated hour, the offset should match the non-dst offset"); t.done(); }, diff --git a/tests/moment-timezone/utc.js b/tests/moment-timezone/utc.js index 33de4b6c..7c234a21 100644 --- a/tests/moment-timezone/utc.js +++ b/tests/moment-timezone/utc.js @@ -11,34 +11,34 @@ exports.utc = { var m = moment("2014-07-10 12:00:00+00:00"), localFormat = m.format(), - localZone = m.zone(); + localOffset = m.utcOffset(); m.tz("TestUTC/Pacific"); - test.equal(m.zone(), 480, "Should change the offset when using moment.fn.tz"); + test.equal(m.utcOffset(), -480, "Should change the offset when using moment.fn.tz"); test.equal(m.format(), "2014-07-10T04:00:00-08:00", "Should change the offset when using moment.fn.tz"); m.utc(); moment.updateOffset(m); - test.equal(m.zone(), 0, "Should set the offset to +00:00 when using moment.fn.utc"); + test.equal(m.utcOffset(), 0, "Should set the offset to +00:00 when using moment.fn.utc"); test.equal(m.format(), "2014-07-10T12:00:00+00:00", "Should change the offset when using moment.fn.utc"); m.tz("TestUTC/Eastern"); - test.equal(m.zone(), 300, "Should change the offset when using moment.fn.tz"); + test.equal(m.utcOffset(), -300, "Should change the offset when using moment.fn.tz"); test.equal(m.format(), "2014-07-10T07:00:00-05:00", "Should change the offset when using moment.fn.tz"); m.utc(); moment.updateOffset(m); - test.equal(m.zone(), 0, "Should set the offset to +00:00 when using moment.fn.utc"); + test.equal(m.utcOffset(), 0, "Should set the offset to +00:00 when using moment.fn.utc"); test.equal(m.format(), "2014-07-10T12:00:00+00:00", "Should change the offset when using moment.fn.utc"); m.local(); moment.updateOffset(m); - test.equal(m.zone(), localZone, "Should reset the offset to local time when using moment.fn.local"); + test.equal(m.utcOffset(), localOffset, "Should reset the offset to local time when using moment.fn.local"); test.equal(m.format(), localFormat, "Should reset the offset to local time when using moment.fn.local"); test.done();