]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Re-add moment.parseZone and add moment.zoned, 108 failed tests left
authorIskren Chernev <iskren.chernev@gmail.com>
Wed, 9 Aug 2017 23:49:36 +0000 (02:49 +0300)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 9 Aug 2017 23:49:36 +0000 (02:49 +0300)
23 files changed:
TODO
src/lib/create/constructors.js
src/lib/create/from-anything.js
src/lib/create/from-array.js
src/lib/create/from-string-and-array.js
src/lib/create/from-string.js
src/lib/create/valid.js
src/lib/moment/get-set.js
src/lib/moment/moment.js
src/lib/timezone/base.js [new file with mode: 0644]
src/lib/timezone/fixed-offset.js
src/lib/timezone/local.js
src/lib/timezone/parsed.js [new file with mode: 0644]
src/lib/units/hour.js
src/lib/units/offset.js
src/lib/units/timestamp.js
src/moment.js
src/test/helpers/dst-time-zone.js [new file with mode: 0644]
src/test/moment/create.js
src/test/moment/getters_setters.js
src/test/moment/start_end_of.js
src/test/moment/utc_offset.js
src/test/moment/zones.js

diff --git a/TODO b/TODO
index 19cee64e3e426b04a6b5c28d7c547d684072e6bf..46cc27e5a3ea2c23fa355d094da03c00f13f8578 100644 (file)
--- a/TODO
+++ b/TODO
@@ -21,7 +21,15 @@ TODO
 * isValid -> compute before "construction", checkOverflow
   - do we have parsing flags if the object is constructed without format?
 * parseZone -> fixedOffset(...., 'parse') + special tmp timezone + check in quick
+  * what to do if parseZone is used but there is no parsed zone? ---> UTC or invalid
+
+  * single format
+  * array format
+  * string only (ISO/RFC2822)
 * Moment should be called from 3 places (invalid, local, utc)
+* _pf gets out-of-sync from config._i/_f/_strict
+    * straigten up interface between different create/parse components
+* rething creationData (isUTC? format?, what for all other cases)
 
 OLD TODO (maybe del)
 * remove _nextDay from moment -> handle it before "creation"
index 699e158567ef0d56e330088a464a65a5d245ee0f..2f570262b6516ec1a558bf1910f6f3b048a5b375 100644 (file)
@@ -1,12 +1,17 @@
 import { createCollect, createInvalid } from './from-anything';
 import { localTimeZone } from '../timezone/local';
 import { fixedTimeZoneForOffset } from '../timezone/fixed-offset';
+import { parsedTimeZone } from '../timezone/parsed';
 import { isMoment } from '../moment/constructor';
 
 export function createUTC (input, format, locale, strict) {
     return createCollect(input, format, locale, strict, fixedTimeZoneForOffset(0));
 }
 
+export function createParsedOffset (input, format, locale, strict) {
+    return createCollect(input, format, locale, strict, parsedTimeZone);
+}
+
 // TODO(Iskren): Enabled 'parse' offset, which uses it from the parsed string.
 export function createFixedOffset () {
     var args = [].slice.apply(arguments),
index 70166dc5fde54c97c6ea84700d9da5fbfcd65931..f1ff9ea8bf217696dedb20e2ade09084dc701a7d 100644 (file)
@@ -40,11 +40,11 @@ function createFromConfig (config) {
         config._i = input = config._locale.preparse(input);
     }
 
-    if (isUndefined(input)) {
+    if (isUndefined(input) && !format) {
         return quickCreateUTC(hooks.now(), config._locale, config._tz);
     } else if (isMoment(input) || isDate(input)) {
         return quickCreateUTC(input.valueOf(), config._locale, config._tz);
-    } else if (isNumber(input)) {
+    } else if (isNumber(input) && !format) {
         return quickCreateUTC(input, config._locale, config._tz);
     } else if (isArray(format)) {
         configFromStringAndArray(config);
@@ -62,10 +62,14 @@ function createFromConfig (config) {
     } else {
         hooks.createFromInputFallback(config);
     }
-    if (!isValid(config) && (config._d == null || !isNaN(config._d.getTime()))) {
+    if (!isValid(config)) {
         return createInvalid(getParsingFlags(config));
     }
 
+    // TODO: parsing flags fail ...
+    if (config._pf.format == null) {
+        config._pf.format = config._f;
+    }
     if (!config._useUTC) {
         return quickCreateLocal(+config._d, config._locale, config._tz, config._pf);
     } else {
@@ -98,14 +102,18 @@ function configFromInput(config) {
 }
 
 export function quickCreateLocal(lts, locale, timeZone, pf) {
+    if (!timeZone.isValid()) {
+        return createInvalid({badTimeZone: true});
+    }
     var localTsOffset = computeOffset(lts, timeZone);
-    // console.log('Local', lts, '###', localTsOffset[0], localTsOffset[1]);
     return new Moment({_ts: localTsOffset[0], _offset: localTsOffset[1], _locale: locale, _tz: timeZone, _pf: pf});
 }
 
 export function quickCreateUTC(uts, locale, timeZone, pf) {
+    if (!timeZone.isValid()) {
+        return createInvalid({badTimeZone: true});
+    }
     var offset = timeZone.offsetFromTimestamp(uts);
-    // console.log('UTC', uts, '###', uts + offset, offset);
     return new Moment({_ts: uts + offset, _offset: offset, _locale: locale, _tz: timeZone, _pf: pf});
 }
 
index c1306511b29137585ad8541318095e244c5f00f8..c7cd3e89ed94f4b0dd77bcd8cb4352a46d75afc4 100644 (file)
@@ -5,14 +5,16 @@ import { daysInYear } from '../units/year';
 import { weekOfYear, weeksInYear, dayOfYearFromWeeks } from '../units/week-calendar-utils';
 import { YEAR, MONTH, DATE, HOUR, MINUTE, SECOND, MILLISECOND } from '../units/constants';
 import { fixedTimeZoneForOffset } from '../timezone/fixed-offset';
+import { parsedTimeZone } from '../timezone/parsed';
 import defaults from '../utils/defaults';
 import getParsingFlags from './parsing-flags';
 import checkOverflow from './check-overflow';
 
 // TODO(Iskren): Call only if needed
+// TODO(Iskren): tz.isValid -- does it make sense?
 function currentDateArray(config, tz) {
     var now = hooks.now(),
-        nowValue = new Date(now + tz.offsetFromTimestamp(now));
+        nowValue = new Date(now + (tz.isValid() ? tz.offsetFromTimestamp(now) : 0));
     return [nowValue.getUTCFullYear(), nowValue.getUTCMonth(), nowValue.getUTCDate()];
 }
 
@@ -28,7 +30,7 @@ export function configFromArray (config) {
     }
 
     // TODO: Implement ignoreOffset config flag
-    if (config._tzm) {
+    if (config._tzm != null) {
         tz = fixedTimeZoneForOffset(config._tzm);
     }
 
@@ -83,11 +85,9 @@ export function configFromArray (config) {
         config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);
         config._useUTC = true;
     }
-    // TODO: Implement fixedOffset 'parse'
-    // if (config._tz === parseTimeZone) {
-    //     config._tz = fixedTimeZoneForOffset(config._tzm);
-    // }
-
+    if (config._tz === parsedTimeZone) {
+        config._tz = fixedTimeZoneForOffset(isNaN(config._tzm) ? 0 : config._tzm);
+    }
 
     if (config._nextDay) {
         config._a[HOUR] = 24;
index 07d119536b8171bff976e90b16c1211c67681b4d..44c79f92fcdaa33748b6a0957aaa4f9d86826b57 100644 (file)
@@ -4,6 +4,16 @@ import getParsingFlags from './parsing-flags';
 import { isValid } from './valid';
 import extend from '../utils/extend';
 
+function cloneConfig(config) {
+    return {
+        _tz : config._tz,
+        _locale : config._locale,
+        _i : config._i,
+        _f : config._f,
+        _strict : config._strict
+    }
+}
+
 // date from string and array of format strings
 export function configFromStringAndArray(config) {
     var tempConfig,
@@ -21,7 +31,7 @@ export function configFromStringAndArray(config) {
 
     for (i = 0; i < config._f.length; i++) {
         currentScore = 0;
-        tempConfig = copyConfig({}, config);
+        tempConfig = cloneConfig(config);
         tempConfig._f = config._f[i];
         configFromStringAndFormat(tempConfig);
 
index e66256bbb7b5a75879186ce20883e046c4ea8894..6aadaa8a8af3510709e552d79d10ef3f8dac523c 100644 (file)
@@ -1,4 +1,5 @@
 import { configFromStringAndFormat } from './from-string-and-format';
+import { isValid } from './valid';
 import { hooks } from '../utils/hooks';
 import { deprecate } from '../utils/deprecate';
 import getParsingFlags from './parsing-flags';
index 4ec47bbf891442369fa6f0b8792326dc1d59dad9..644d5289eb78cabef0c95ef137f1204ed5dae2b5 100644 (file)
@@ -9,7 +9,7 @@ export function isValid(m) {
         var parsedParts = some.call(flags.parsedDateParts, function (i) {
             return i != null;
         });
-        var isNowValid = !isNaN(m._d.getTime()) &&
+        var isNowValid = m._d != null && !isNaN(m._d.getTime()) &&
             flags.overflow < 0 &&
             !flags.empty &&
             !flags.invalidMonth &&
index 82a61ca0d6c465000a8fb3b55e95ba85d0a75ccf..77a688470f2cd4e10bb84630069ba16f9a8609f0 100644 (file)
@@ -29,12 +29,12 @@ function set (mom, unit, value, msCoef) {
     var d, uts;
     // console.log('SET', arguments);
     if (msCoef != null) {
-        // this is one of ms, second, minute, hour
+        // this is one of ms, second, minute
         uts = mom.valueOf();
         uts += (value - get(mom, unit)) * msCoef;
         return quickCreateUTC(uts, mom._locale, mom._tz);
     } else {
-        // day or year, NOT month
+        // hour, day or year, NOT month
         d = new Date(mom._d);
         d['setUTC' + unit](value);
         return quickCreateLocal(d.valueOf(), mom._locale, mom._tz);
index 78436cf059f3caf85912b7b789bf31b4ca2ddcb6..0352ad0c18bcb439c2e5b70e3f542e087f9e75a8 100644 (file)
@@ -1,4 +1,4 @@
-import { createLocal, createUTC, createFixedOffset } from '../create/constructors';
+import { createLocal, createUTC, createFixedOffset, createParsedOffset, createZoned } from '../create/constructors';
 import { createInvalid } from '../create/from-anything';
 import { isMoment } from './constructor';
 import { min, max } from './min-max';
@@ -22,6 +22,8 @@ export {
     createUnix,
     createLocal,
     createFixedOffset,
+    createParsedOffset,
+    createZoned,
     createInvalid,
     momentPrototype
 };
diff --git a/src/lib/timezone/base.js b/src/lib/timezone/base.js
new file mode 100644 (file)
index 0000000..69da738
--- /dev/null
@@ -0,0 +1,6 @@
+export default function BaseTimeZone() {
+}
+
+BaseTimeZone.prototype.isValid = function() {
+    return true;
+}
index aa77329481f136dc6762a087819053dd55a79606..066e16b9a13d90f0e1ade06a9e2a1ddcddd22d0a 100644 (file)
@@ -1,4 +1,6 @@
 import hasOwnProp from '../utils/has-own-prop';
+import BaseTimeZone from './base';
+import extend from '../utils/extend';
 
 var memo = {};
 
@@ -14,6 +16,8 @@ FixedOffsetTimeZone.fromOffset = function (offset) {
     return memo[offset];
 };
 
+FixedOffsetTimeZone.prototype = extend({}, BaseTimeZone.prototype);
+
 FixedOffsetTimeZone.prototype.offsetFromTimestamp = function (uts) {
     return this.offsetMs;
 };
index acf77ebef1ff23094a9dcbae571ec47bff94455f..75e12d2e65b5c372aec066b3e0dc83bfb1190fda 100644 (file)
@@ -1,6 +1,11 @@
+import extend from '../utils/extend';
+import BaseTimeZone from './base';
+
 function LocalTimeZone() {
 }
 
+LocalTimeZone.prototype = extend({}, BaseTimeZone.prototype);
+
 LocalTimeZone.prototype.offsetFromTimestamp = function (uts) {
     return -(new Date(uts).getTimezoneOffset()) * 60 * 1000;
 };
diff --git a/src/lib/timezone/parsed.js b/src/lib/timezone/parsed.js
new file mode 100644 (file)
index 0000000..f64dfd3
--- /dev/null
@@ -0,0 +1,13 @@
+import extend from '../utils/extend';
+import BaseTimeZone from './base';
+
+function ParsedTimeZone() {
+}
+
+ParsedTimeZone.prototype = extend({}, BaseTimeZone.prototype);
+
+ParsedTimeZone.prototype.isValid = function () {
+    return false;
+}
+
+export var parsedTimeZone = new ParsedTimeZone();
index eeca0dc625d0e9231062cfe37caee7bf26490125..68305d46ce0cdfc1cf9fdcca384f4ef403c8492a 100644 (file)
@@ -138,7 +138,7 @@ export function localeMeridiem (hours, minutes, isLower) {
 // specified which hour he wants. So trying to maintain the same hour (in
 // a new timezone) makes sense. Adding/subtracting hours does not follow
 // this rule.
-export var getSetHour = makeGetSet('Hours', 60 * 60 * 1000);
+export var getSetHour = makeGetSet('Hours');
 
 // PRIORITY
 
index 52347a42fcd5d9ebc6377db55204a6cea4b090e7..3914bdb43f1a659a401a53fc25f7e835023f06ea 100644 (file)
@@ -247,13 +247,13 @@ export function isDaylightSavingTime () {
 // }
 
 export function isLocal () {
-    return this._tz.type === 'local';
+    return this.isValid() && this._tz.type === 'local';
 }
 
 export function isUtcOffset () {
-    return this._tz.type === 'fixed-offset';
+    return this.isValid() && this._tz.type === 'fixed-offset';
 }
 
 export function isUtc () {
-    return this._tz.type === 'fixed-offset' && this._tz.offset === 0;
+    return this.isValid() && this._tz.type === 'fixed-offset' && this._tz.offset === 0;
 }
index a49e1e4b852e1c01a04c8655534e9e74947e7cc1..72a76c2c468fb7e0fcbd3fb352d7cae248e39560 100644 (file)
@@ -14,7 +14,9 @@ addRegexToken('x', matchSigned);
 addRegexToken('X', matchTimestamp);
 addParseToken('X', function (input, array, config) {
     config._d = new Date(parseFloat(input, 10) * 1000);
+    config._useUTC = true;
 });
 addParseToken('x', function (input, array, config) {
     config._d = new Date(toInt(input));
+    config._useUTC = true;
 });
index fe7664f367e7fad8b4082f840352d41c8cac3138..829fa385b49483b6411aaa3655f5e6445d15fc1c 100644 (file)
@@ -19,7 +19,9 @@ import {
     createUnix      as unix,
     createLocal     as local,
     createInvalid   as invalid,
-    createFixedOffset    as fixedOffset
+    createFixedOffset as fixedOffset,
+    createParsedOffset as parseZone,
+    createZoned as zoned
 } from './lib/moment/moment';
 
 import {
@@ -57,6 +59,8 @@ moment.min                   = min;
 moment.max                   = max;
 moment.now                   = now;
 moment.utc                   = utc;
+moment.parseZone             = parseZone;
+moment.zoned                 = zoned;
 moment.unix                  = unix;
 moment.months                = months;
 moment.isDate                = isDate;
diff --git a/src/test/helpers/dst-time-zone.js b/src/test/helpers/dst-time-zone.js
new file mode 100644 (file)
index 0000000..5023f35
--- /dev/null
@@ -0,0 +1,24 @@
+import BaseTimeZone from '../../lib/timezone/base';
+import extend from '../../lib/utils/extend';
+
+function DSTTimeZone(dstAt, oldOffset, newOffset) {
+    BaseTimeZone.call(this);
+
+    this.dstAt = dstAt;
+    this.oldOffsetMs = oldOffset * 60 * 60 * 1000;
+    this.newOffsetMs = newOffset * 60 * 60 * 1000;
+}
+
+DSTTimeZone.prototype = extend({}, BaseTimeZone.prototype);
+
+DSTTimeZone.prototype.offsetFromTimestamp = function (utc) {
+    if (utc < this.dstAt) {
+        return this.oldOffsetMs;
+    } else {
+        return this.newOffsetMs;
+    }
+}
+
+export var dstTimeZone = function (dstAt, oldOffset, newOffset) {
+    return new DSTTimeZone(dstAt, oldOffset, newOffset);
+}
index 9262966d9659732b6e886143aa7e79505fe2b7fa..1d22fbbcd28c2039abd88a5e4a32bc4588aa6199 100644 (file)
@@ -120,15 +120,16 @@ test('cloning moment works with weird clones', function (assert) {
     assert.equal(+moment(extend({}, nowu)), +nowu, 'cloning extend-ed utc now is utc now');
 });
 
-test('cloning respects moment.momentProperties', function (assert) {
-    var m = moment();
+// TODO: Drop this altogether?
+// test('cloning respects moment.momentProperties', function (assert) {
+//     var m = moment();
 
-    assert.equal(moment(m)._special, undefined, 'cloning ignores extra properties');
-    m._special = 'bacon';
-    moment.momentProperties.push('_special');
-    assert.equal(moment(m)._special, 'bacon', 'cloning respects momentProperties');
-    moment.momentProperties.pop();
-});
+//     assert.equal(moment(m)._special, undefined, 'cloning ignores extra properties');
+//     m._special = 'bacon';
+//     moment.momentProperties.push('_special');
+//     assert.equal(moment(m)._special, 'bacon', 'cloning respects momentProperties');
+//     moment.momentProperties.pop();
+// });
 
 test('undefined', function (assert) {
     assert.ok(moment().toDate() instanceof Date, 'undefined');
@@ -405,10 +406,10 @@ test('string with array of formats', function (assert) {
 
     assert.equal(moment('11-02-10', ['MM.DD.YY', 'DD-MM-YY']).format('MM DD YYYY'), '02 11 2010', 'escape RegExp special characters on comparing');
 
-    assert.equal(moment('13-10-98', ['DD MM YY', 'DD MM YYYY'])._f, 'DD MM YY', 'use two digit year');
-    assert.equal(moment('13-10-1998', ['DD MM YY', 'DD MM YYYY'])._f, 'DD MM YYYY', 'use four digit year');
+    assert.equal(moment('13-10-98', ['DD MM YY', 'DD MM YYYY']).parsingFlags().format, 'DD MM YY', 'use two digit year');
+    assert.equal(moment('13-10-1998', ['DD MM YY', 'DD MM YYYY']).parsingFlags().format, 'DD MM YYYY', 'use four digit year');
 
-    assert.equal(moment('01', ['MM', 'DD'])._f, 'MM', 'Should use first valid format');
+    assert.equal(moment('01', ['MM', 'DD']).parsingFlags().format, 'MM', 'Should use first valid format');
 
     assert.equal(moment('Thursday 8:30pm', ['dddd h:mma']).format('YYYY MM DD dddd h:mma'), thursdayForCurrentWeek + ' Thursday 8:30pm', 'Default to current week');
 });
@@ -451,11 +452,11 @@ test('explicit cloning', function (assert) {
     assert.equal(momentA.month(), 5, 'momentB keeps original month');
 });
 
-test('cloning carrying over utc mode', function (assert) {
-    assert.equal(moment(moment().local())._isUTC, false, 'A cloned local moment should have _isUTC == false');
-    assert.equal(moment(moment().utc())._isUTC, true, 'A cloned utc moment should have _isUTC == true');
-    assert.equal(moment(moment())._isUTC, false, 'A cloned local moment should have _isUTC == false');
-    assert.equal(moment(moment.utc())._isUTC, true, 'A cloned utc moment should have _isUTC == true');
+test('cloning uses utc mode of new constructor', function (assert) {
+    assert.equal(moment(moment().local()).isUTC(), false, 'local(local) -> local');
+    assert.equal(moment(moment().utc()).isUTC(), false, 'local(utc) -> local');
+    assert.equal(moment.utc(moment().local()).isUTC(), true, 'utc(local) -> utc');
+    assert.equal(moment.utc(moment().utc()).isUTC(), true, 'utc(utc) -> utc');
 });
 
 test('parsing RFC 2822', function (assert) {
@@ -778,15 +779,15 @@ test('parsing ISO with Z', function (assert) {
 });
 
 test('parsing iso with T', function (assert) {
-    assert.equal(moment('2011-10-08T18')._f, 'YYYY-MM-DDTHH', 'should include \'T\' in the format');
-    assert.equal(moment('2011-10-08T18:20')._f, 'YYYY-MM-DDTHH:mm', 'should include \'T\' in the format');
-    assert.equal(moment('2011-10-08T18:20:13')._f, 'YYYY-MM-DDTHH:mm:ss', 'should include \'T\' in the format');
-    assert.equal(moment('2011-10-08T18:20:13.321')._f, 'YYYY-MM-DDTHH:mm:ss.SSSS', 'should include \'T\' in the format');
-
-    assert.equal(moment('2011-10-08 18')._f, 'YYYY-MM-DD HH', 'should not include \'T\' in the format');
-    assert.equal(moment('2011-10-08 18:20')._f, 'YYYY-MM-DD HH:mm', 'should not include \'T\' in the format');
-    assert.equal(moment('2011-10-08 18:20:13')._f, 'YYYY-MM-DD HH:mm:ss', 'should not include \'T\' in the format');
-    assert.equal(moment('2011-10-08 18:20:13.321')._f, 'YYYY-MM-DD HH:mm:ss.SSSS', 'should not include \'T\' in the format');
+    assert.equal(moment('2011-10-08T18').parsingFlags().format, 'YYYY-MM-DDTHH', 'should include \'T\' in the format');
+    assert.equal(moment('2011-10-08T18:20').parsingFlags().format, 'YYYY-MM-DDTHH:mm', 'should include \'T\' in the format');
+    assert.equal(moment('2011-10-08T18:20:13').parsingFlags().format, 'YYYY-MM-DDTHH:mm:ss', 'should include \'T\' in the format');
+    assert.equal(moment('2011-10-08T18:20:13.321').parsingFlags().format, 'YYYY-MM-DDTHH:mm:ss.SSSS', 'should include \'T\' in the format');
+
+    assert.equal(moment('2011-10-08 18').parsingFlags().format, 'YYYY-MM-DD HH', 'should not include \'T\' in the format');
+    assert.equal(moment('2011-10-08 18:20').parsingFlags().format, 'YYYY-MM-DD HH:mm', 'should not include \'T\' in the format');
+    assert.equal(moment('2011-10-08 18:20:13').parsingFlags().format, 'YYYY-MM-DD HH:mm:ss', 'should not include \'T\' in the format');
+    assert.equal(moment('2011-10-08 18:20:13.321').parsingFlags().format, 'YYYY-MM-DD HH:mm:ss.SSSS', 'should not include \'T\' in the format');
 });
 
 test('parsing iso Z timezone', function (assert) {
index 5f28c60310b4e400c9e637dbe96ea69d62b428f4..ced06637334e1edad5e35f3e18778070060df9f1 100644 (file)
@@ -1,5 +1,6 @@
 import { module, test } from '../qunit';
 import moment from '../../moment';
+import { dstTimeZone } from '../helpers/dst-time-zone';
 
 module('getters and setters');
 
@@ -266,49 +267,33 @@ test('string setters', function (assert) {
 });
 
 test('setters across DST +1', function (assert) {
-    var oldUpdateOffset = moment.updateOffset,
-        // Based on a real story somewhere in America/Los_Angeles
-        dstAt = moment('2014-03-09T02:00:00-08:00').parseZone(),
-        m;
-
-    moment.updateOffset = function (mom, keepTime) {
-        if (mom.isBefore(dstAt)) {
-            return mom.utcOffset(-8, keepTime);
-        }
-        return mom.utcOffset(-7, keepTime);
-    };
-
-    m = moment('2014-03-15T00:00:00-07:00').parseZone();
+    var // Based on a real story somewhere in America/Los_Angeles
+        dstAt = moment.parseZone('2014-03-09T02:00:00-08:00'),
+        m,
+        tz = dstTimeZone(+dstAt, -8, -7);
+
+    m = moment.zoned('2014-03-15T00:00:00', tz);
+    assert.equal(+m, +moment.parseZone('2014-03-15T00:00:00-07:00'), 'initial');
     assert.equal(m.year(2013).format(), '2013-03-15T00:00:00-08:00', 'year across +1');
     assert.equal(m.month(0).format(), '2014-01-15T00:00:00-08:00', 'month across +1');
     assert.equal(m.date(1).format(), '2014-03-01T00:00:00-08:00', 'date across +1');
 
-    m = moment('2014-03-09T03:05:00-07:00').parseZone();
+    m = moment.zoned('2014-03-09T03:05:00-07:00', tz);
     assert.equal(m.hour(0).format(), '2014-03-09T00:05:00-08:00', 'hour across +1');
-
-    moment.updateOffset = oldUpdateOffset;
 });
 
 test('setters across DST -1', function (assert) {
-    var oldUpdateOffset = moment.updateOffset,
-        // Based on a real story somewhere in America/Los_Angeles
-        dstAt = moment('2014-11-02T02:00:00-07:00').parseZone(),
-        m;
-
-    moment.updateOffset = function (mom, keepTime) {
-        if (mom.isBefore(dstAt)) {
-            return mom.utcOffset(-7, keepTime);
-        }
-        return mom.utcOffset(-8, keepTime);
-    };
-
-    m = moment('2014-11-15T00:00:00-08:00').parseZone();
+    var // Based on a real story somewhere in America/Los_Angeles
+        dstAt = moment.parseZone('2014-11-02T02:00:00-07:00'),
+        m,
+        tz = dstTimeZone(+dstAt, -7, -8);
+
+    m = moment.zoned('2014-11-15T00:00:00', tz);
+    assert.equal(+m, +moment.parseZone('2014-11-15T00:00:00-08:00'), 'initial');
     assert.equal(m.year(2013).format(), '2013-11-15T00:00:00-07:00', 'year across -1');
     assert.equal(m.month(0).format(), '2014-01-15T00:00:00-07:00', 'month across -1');
     assert.equal(m.date(1).format(), '2014-11-01T00:00:00-07:00', 'date across -1');
 
-    m = moment('2014-11-02T03:30:00-08:00').parseZone();
+    m = moment.zoned('2014-11-02T03:30:00-08:00', tz);
     assert.equal(m.hour(0).format(), '2014-11-02T00:30:00-07:00', 'hour across -1');
-
-    moment.updateOffset = oldUpdateOffset;
 });
index 9f59bdba1f08572afbd9def16de4e21f03934a7c..31f5c004ec2e958d31dffcd748b135229622fbcb 100644 (file)
@@ -311,7 +311,7 @@ test('end of second', function (assert) {
 test('startOf across DST +1', function (assert) {
     var oldUpdateOffset = moment.updateOffset,
         // Based on a real story somewhere in America/Los_Angeles
-        dstAt = moment('2014-03-09T02:00:00-08:00').parseZone(),
+        dstAt = moment.parseZone('2014-03-09T02:00:00-08:00'),
         m;
 
     moment.updateOffset = function (mom, keepTime) {
@@ -321,17 +321,17 @@ test('startOf across DST +1', function (assert) {
         return mom.utcOffset(-7, keepTime);
     };
 
-    m = moment('2014-03-15T00:00:00-07:00').parseZone();
+    m = moment.parseZone('2014-03-15T00:00:00-07:00');
     assert.equal(m.startOf('y').format(), '2014-01-01T00:00:00-08:00', 'startOf(\'year\') across +1');
     assert.equal(m.startOf('M').format(), '2014-03-01T00:00:00-08:00', 'startOf(\'month\') across +1');
 
-    m = moment('2014-03-09T09:00:00-07:00').parseZone();
+    m = moment.parseZone('2014-03-09T09:00:00-07:00');
     assert.equal(m.startOf('d').format(), '2014-03-09T00:00:00-08:00', 'startOf(\'day\') across +1');
 
-    m = moment('2014-03-09T03:05:00-07:00').parseZone();
+    m = moment.parseZone('2014-03-09T03:05:00-07:00');
     assert.equal(m.startOf('h').format(), '2014-03-09T03:00:00-07:00', 'startOf(\'hour\') after +1');
 
-    m = moment('2014-03-09T01:35:00-08:00').parseZone();
+    m = moment.parseZone('2014-03-09T01:35:00-08:00');
     assert.equal(m.startOf('h').format(), '2014-03-09T01:00:00-08:00', 'startOf(\'hour\') before +1');
 
     // There is no such time as 2:30-7 to try startOf('hour') across that
@@ -342,7 +342,7 @@ test('startOf across DST +1', function (assert) {
 test('startOf across DST -1', function (assert) {
     var oldUpdateOffset = moment.updateOffset,
         // Based on a real story somewhere in America/Los_Angeles
-        dstAt = moment('2014-11-02T02:00:00-07:00').parseZone(),
+        dstAt = moment.parseZone('2014-11-02T02:00:00-07:00'),
         m;
 
     moment.updateOffset = function (mom, keepTime) {
@@ -352,19 +352,19 @@ test('startOf across DST -1', function (assert) {
         return mom.utcOffset(-8, keepTime);
     };
 
-    m = moment('2014-11-15T00:00:00-08:00').parseZone();
+    m = moment.parseZone('2014-11-15T00:00:00-08:00');
     assert.equal(m.startOf('y').format(), '2014-01-01T00:00:00-07:00', 'startOf(\'year\') across -1');
     assert.equal(m.startOf('M').format(), '2014-11-01T00:00:00-07:00', 'startOf(\'month\') across -1');
 
-    m = moment('2014-11-02T09:00:00-08:00').parseZone();
+    m = moment.parseZone('2014-11-02T09:00:00-08:00');
     assert.equal(m.startOf('d').format(), '2014-11-02T00:00:00-07:00', 'startOf(\'day\') across -1');
 
     // note that utc offset is -8
-    m = moment('2014-11-02T01:30:00-08:00').parseZone();
+    m = moment.parseZone('2014-11-02T01:30:00-08:00');
     assert.equal(m.startOf('h').format(), '2014-11-02T01:00:00-08:00', 'startOf(\'hour\') after +1');
 
     // note that utc offset is -7
-    m = moment('2014-11-02T01:30:00-07:00').parseZone();
+    m = moment.parseZone('2014-11-02T01:30:00-07:00');
     assert.equal(m.startOf('h').format(), '2014-11-02T01:00:00-07:00', 'startOf(\'hour\') before +1');
 
     moment.updateOffset = oldUpdateOffset;
index 52d9db5ff7496fe5443ac74eef30710f764ac185..dd0ba4589b80da5d5a0fff65369cd37330499737 100644 (file)
@@ -422,13 +422,13 @@ test('hours alignment with other zone', function (assert) {
 });
 
 test('parse zone', function (assert) {
-    var m = moment('2013-01-01T00:00:00-13:00').parseZone();
+    var m = moment.parseZone('2013-01-01T00:00:00-13:00');
     assert.equal(m.utcOffset(), -13 * 60);
     assert.equal(m.hours(), 0);
 });
 
 test('parse UTC zone', function (assert) {
-    var m = moment('2013-01-01T05:00:00+00:00').parseZone();
+    var m = moment.parseZone('2013-01-01T05:00:00+00:00');
     assert.equal(m.utcOffset(), 0);
     assert.equal(m.hours(), 5);
 });
@@ -450,13 +450,13 @@ test('parse zone with more arguments', function (assert) {
 });
 
 test('parse zone with a timezone from the format string', function (assert) {
-    var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY ZZ #####').parseZone();
+    var m = moment.parseZone('11-12-2013 -0400 +1100', 'DD-MM-YYYY ZZ #####');
 
     assert.equal(m.utcOffset(), -4 * 60);
 });
 
 test('parse zone without a timezone included in the format string', function (assert) {
-    var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY').parseZone();
+    var m = moment.parseZone('11-12-2013 -0400 +1100', 'DD-MM-YYYY');
 
     assert.equal(m.utcOffset(), 11 * 60);
 });
index 181c13f1ec773bc68a589bcb8e6776a5150852a7..237580af147983f5f9f6fe812956de8f8ce45ddb 100644 (file)
@@ -368,7 +368,7 @@ test('hours alignment with other zone', function (assert) {
 });
 
 test('parse zone', function (assert) {
-    var m = moment('2013-01-01T00:00:00-13:00').parseZone();
+    var m = moment.parseZone('2013-01-01T00:00:00-13:00');
     assert.equal(m.zone(), 13 * 60);
     assert.equal(m.hours(), 0);
 });
@@ -397,7 +397,7 @@ test('parse zone with a timezone from the format string', function (assert) {
 });
 
 test('parse zone without a timezone included in the format string', function (assert) {
-    var m = moment('11-12-2013 -0400 +1100', 'DD-MM-YYYY').parseZone();
+    var m = moment.parseZone('11-12-2013 -0400 +1100', 'DD-MM-YYYY');
 
     assert.equal(m.zone(), -11 * 60);
 });