From: Iskren Chernev Date: Sun, 12 Jul 2015 23:09:19 +0000 (-0700) Subject: Fix isDSTShifted, fixes #2141 X-Git-Tag: 2.10.5~7^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=945c05829d831e5f9478c9e573fdb85d3342b24f;p=thirdparty%2Fmoment.git Fix isDSTShifted, fixes #2141 --- diff --git a/src/lib/create/from-anything.js b/src/lib/create/from-anything.js index 4b836c0fa..5a69dc55b 100644 --- a/src/lib/create/from-anything.js +++ b/src/lib/create/from-anything.js @@ -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) { diff --git a/src/lib/units/offset.js b/src/lib/units/offset.js index c9b692239..33288c0bf 100644 --- a/src/lib/units/offset.js +++ b/src/lib/units/offset.js @@ -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 () {