Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer moment.fn.utcOffset to moment.fn.zone #157

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion moment-timezone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions tests/helpers/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -29,4 +29,4 @@ module.exports = {
testYear(test, name, expected);
};
}
};
};
64 changes: 32 additions & 32 deletions tests/moment-timezone/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand All @@ -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();
},
Expand All @@ -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();
},
Expand All @@ -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();
},
Expand All @@ -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();
},
Expand All @@ -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();
},
Expand All @@ -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();
},
Expand All @@ -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();
},
Expand Down
12 changes: 6 additions & 6 deletions tests/moment-timezone/utc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down