]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fix makeAs to work with zoned moments
authorIskren Chernev <iskren.chernev@gmail.com>
Wed, 22 Oct 2014 18:50:29 +0000 (11:50 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Mon, 17 Nov 2014 05:16:39 +0000 (21:16 -0800)
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

index 1cc739bd4743eb44a8e439df8292420e3b23eff3..40ab6880bdd02b53ec9aad8e7e9aa6d4938bc88b 100644 (file)
--- a/moment.js
+++ b/moment.js
 
     // 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();
+        }
     }
 
     /************************************