]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fix isDSTShifted, fixes #2141
authorIskren Chernev <iskren.chernev@gmail.com>
Sun, 12 Jul 2015 23:09:19 +0000 (16:09 -0700)
committerIskren Chernev <iskren.chernev@gmail.com>
Sun, 26 Jul 2015 04:49:41 +0000 (21:49 -0700)
src/lib/create/from-anything.js
src/lib/units/offset.js

index 4b836c0faef448738819472f2d560e352f926305..5a69dc55b9f0da62062e02a2864422ce05a3a87f 100644 (file)
@@ -14,9 +14,19 @@ import { configFromArray }           from './from-array';
 import { configFromObject }          from './from-object';
 
 function createFromConfig (config) {
+    var res = new Moment(checkOverflow(prepareConfig(config)));
+    if (res._nextDay) {
+        // Adding is smart enough around DST
+        res.add(1, 'd');
+        res._nextDay = undefined;
+    }
+
+    return res;
+}
+
+export function prepareConfig (config) {
     var input = config._i,
-        format = config._f,
-        res;
+        format = config._f;
 
     config._locale = config._locale || getLocale(config._l);
 
@@ -40,14 +50,7 @@ function createFromConfig (config) {
         configFromInput(config);
     }
 
-    res = new Moment(checkOverflow(config));
-    if (res._nextDay) {
-        // Adding is smart enough around DST
-        res.add(1, 'd');
-        res._nextDay = undefined;
-    }
-
-    return res;
+    return config;
 }
 
 function configFromInput(config) {
index c9b692239449edd0e3adbc4d688c5fd9c6c318b5..33288c0bf4c89ac25051204558341801351b80b1 100644 (file)
@@ -1,11 +1,12 @@
 import zeroFill from '../utils/zero-fill';
 import { createDuration } from '../duration/create';
 import { addSubtract } from '../moment/add-subtract';
-import { isMoment } from '../moment/constructor';
+import { isMoment, copyConfig } from '../moment/constructor';
 import { addFormatToken } from '../format/format';
 import { addRegexToken, matchOffset } from '../parse/regex';
 import { addParseToken } from '../parse/token';
 import { createLocal } from '../create/local';
+import { prepareConfig } from '../create/from-anything';
 import { createUTC } from '../create/utc';
 import isDate from '../utils/is-date';
 import toInt from '../utils/to-int';
@@ -179,12 +180,24 @@ export function isDaylightSavingTime () {
 }
 
 export function isDaylightSavingTimeShifted () {
-    if (this._a) {
-        var other = this._isUTC ? createUTC(this._a) : createLocal(this._a);
-        return this.isValid() && compareArrays(this._a, other.toArray()) > 0;
+    if (typeof this._isDSTShifted !== 'undefined') {
+        return this._isDSTShifted;
     }
 
-    return false;
+    var c = {};
+
+    copyConfig(c, this);
+    c = prepareConfig(c);
+
+    if (c._a) {
+        var other = c._isUTC ? createUTC(c._a) : createLocal(c._a);
+        this._isDSTShifted = this.isValid() &&
+            compareArrays(c._a, other.toArray()) > 0;
+    } else {
+        this._isDSTShifted = false;
+    }
+
+    return this._isDSTShifted;
 }
 
 export function isLocal () {