From 014cf0c58c51d39819b6f1136ea2ee24f646e572 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 26 Jun 2017 20:58:04 -0500 Subject: [PATCH] Convert to tz keeping wall time --- moment-timezone.js | 4 ++-- tests/moment-timezone/utc.js | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/moment-timezone.js b/moment-timezone.js index 644abc61..71ab9ac0 100644 --- a/moment-timezone.js +++ b/moment-timezone.js @@ -545,11 +545,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/."); } diff --git a/tests/moment-timezone/utc.js b/tests/moment-timezone/utc.js index 9690b6a8..ce78026a 100644 --- a/tests/moment-timezone/utc.js +++ b/tests/moment-timezone/utc.js @@ -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(); } };