From: Iskren Chernev Date: Wed, 22 Oct 2014 18:50:29 +0000 (-0700) Subject: Fix makeAs to work with zoned moments X-Git-Tag: 2.8.4~26^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b822111d6cc806b8da11cdf4aaa309a3fcd9091c;p=thirdparty%2Fmoment.git 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 --- 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(); + } } /************************************