From b822111d6cc806b8da11cdf4aaa309a3fcd9091c Mon Sep 17 00:00:00 2001 From: Iskren Chernev Date: Wed, 22 Oct 2014 11:50:29 -0700 Subject: [PATCH] Fix makeAs to work with zoned moments Clone the model to get all plugin data (like zones), than move the time so that it matches the input and recompute the timezone. Closes #1952, #1956, #1772 --- moment.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/moment.js b/moment.js index 1cc739bd4..40ab6880b 100644 --- a/moment.js +++ b/moment.js @@ -776,8 +776,18 @@ // Return a moment from input, that is local/utc/zone equivalent to model. function makeAs(input, model) { - return model._isUTC ? moment(input).zone(model._offset || 0) : - moment(input).local(); + var res, diff; + if (model._isUTC) { + res = model.clone(); + diff = (moment.isMoment(input) || isDate(input) ? + +input : +moment(input)) - (+res); + // Use low-level api, because this fn is low-level api. + res._d.setTime(+res._d + diff); + moment.updateOffset(res, false); + return res; + } else { + return moment(input).local(); + } } /************************************ -- 2.47.3