Skip to content

Commit

Permalink
Merge pull request #505 from Sornelo/wall_time
Browse files Browse the repository at this point in the history
Convert to tz keeping wall time
  • Loading branch information
mattjohnsonpint committed Aug 29, 2017
2 parents 8ed751a + 014cf0c commit ac7e723
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions moment-timezone.js
Expand Up @@ -550,11 +550,11 @@
}
};

fn.tz = function (name) {
fn.tz = function (name, keepTime) {
if (name) {
this._z = getZone(name);
if (this._z) {
moment.updateOffset(this);
moment.updateOffset(this, keepTime);
} else {
logError("Moment Timezone has no data for " + name + ". See http://momentjs.com/timezone/docs/#/data-loading/.");
}
Expand Down
5 changes: 5 additions & 0 deletions tests/moment-timezone/utc.js
Expand Up @@ -42,6 +42,11 @@ exports.utc = {
test.equal(helpers.getUTCOffset(m), 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");

m = moment('2017-01-01T00:00:00');
var utcWallTimeFormat = m.clone().utcOffset('-05:00', true).format();
m.tz('America/New_York', true);
test.equal(m.format(), utcWallTimeFormat, "Should change the offset while keeping wall time when passing an optional parameter to moment.fn.tz");

test.done();
}
};

0 comments on commit ac7e723

Please sign in to comment.