]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Revert "Merge pull request #5599 from Alanscut:issue_4985"
authorIskren Chernev <me@iskren.info>
Tue, 26 Dec 2023 18:05:03 +0000 (20:05 +0200)
committerIskren Chernev <me@iskren.info>
Tue, 26 Dec 2023 18:05:03 +0000 (20:05 +0200)
This reverts commit c8785e7d6acc94464b3d54c866b3f5a08d3df74e, reversing
changes made to b4e0676927f8acae8a3e8fea45fe47a8f1ddc62f.

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-and-format.js
src/lib/create/from-string.js
src/lib/moment/constructor.js
src/lib/utils/create-error.js [deleted file]
src/test/moment/create.js

index 47934921047b7aa8d518d85378e547cbea7f87e4..0c5d772364e1e46d36ff4302691270f6120d35a3 100644 (file)
@@ -17,7 +17,6 @@ import { configFromStringAndFormat } from './from-string-and-format';
 import { configFromString } from './from-string';
 import { configFromArray } from './from-array';
 import { configFromObject } from './from-object';
-import createError from '../utils/create-error';
 
 function createFromConfig(config) {
     var res = new Moment(checkOverflow(prepareConfig(config)));
@@ -84,12 +83,6 @@ function configFromInput(config) {
     } else {
         hooks.createFromInputFallback(config);
     }
-    createError(
-        config._i + ' failed to build a Date using `new Date()`',
-        config._d,
-        config._i,
-        config._f
-    );
 }
 
 export function createLocalOrUTC(input, format, locale, strict, isUTC) {
index 365e7cd8536465f9482d1ec988eae6afa5e0c814..610d802da41462dc767712d5e40ef1c358d5361f 100644 (file)
@@ -18,7 +18,6 @@ import {
 import { createLocal } from './local';
 import defaults from '../utils/defaults';
 import getParsingFlags from './parsing-flags';
-import createError from '../utils/create-error';
 
 function currentDateArray(config) {
     // hooks is actually the exported moment object
@@ -102,12 +101,6 @@ export function configFromArray(config) {
         null,
         input
     );
-    createError(
-        config._i + ' failed to build a Date using `new Date()`',
-        config._d,
-        config._i,
-        config._f
-    );
     expectedWeekday = config._useUTC
         ? config._d.getUTCDay()
         : config._d.getDay();
index 180201069b81f974255e59087be1989f73859a70..4e641674271b199d7e2d57fbc7ae88a44465fe5f 100644 (file)
@@ -3,7 +3,6 @@ import { configFromStringAndFormat } from './from-string-and-format';
 import getParsingFlags from './parsing-flags';
 import { isValid } from './valid';
 import extend from '../utils/extend';
-import createError from '../utils/create-error';
 
 // date from string and array of format strings
 export function configFromStringAndArray(config) {
@@ -19,12 +18,6 @@ export function configFromStringAndArray(config) {
     if (configfLen === 0) {
         getParsingFlags(config).invalidFormat = true;
         config._d = new Date(NaN);
-        createError(
-            "Invalid `format`, its length shouldn't be 0",
-            config._d,
-            config._i,
-            config._f
-        );
         return;
     }
 
index 063b09459645d729660f96111959de385c7519a3..82d60d52039344b7c246093116997023bb6d63a4 100644 (file)
@@ -11,7 +11,6 @@ import checkOverflow from './check-overflow';
 import { YEAR, HOUR } from '../units/constants';
 import { hooks } from '../utils/hooks';
 import getParsingFlags from './parsing-flags';
-import createError from '../utils/create-error';
 
 // constant that refers to the ISO standard
 hooks.ISO_8601 = function () {};
@@ -24,22 +23,10 @@ export function configFromStringAndFormat(config) {
     // TODO: Move this to another part of the creation flow to prevent circular deps
     if (config._f === hooks.ISO_8601) {
         configFromISO(config);
-        createError(
-            config._i + ' does not match the `ISO 8601` standard',
-            config._d,
-            config._i,
-            config._f
-        );
         return;
     }
     if (config._f === hooks.RFC_2822) {
         configFromRFC2822(config);
-        createError(
-            config._i + ' does not match the `RFC 2822` standard',
-            config._d,
-            config._i,
-            config._f
-        );
         return;
     }
     config._a = [];
index b50e77e614e3220b09a0d0bbcc177357267aab05..58739b9d7c6e49936a18808bee7b25f39bcd9dc3 100644 (file)
@@ -5,7 +5,6 @@ import { deprecate } from '../utils/deprecate';
 import getParsingFlags from './parsing-flags';
 import { defaultLocaleMonthsShort } from '../units/month';
 import { defaultLocaleWeekdaysShort } from '../units/day-of-week';
-import createError from '../utils/create-error';
 
 // iso 8601 regex
 // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)
@@ -224,36 +223,21 @@ export function configFromString(config) {
     var matched = aspNetJsonRegex.exec(config._i);
     if (matched !== null) {
         config._d = new Date(+matched[1]);
-        return createError(
-            matched[1] + ' failed to build a Date using `new Date()`',
-            config._d,
-            config._i,
-            config._f
-        );
+        return;
     }
 
     configFromISO(config);
     if (config._isValid === false) {
         delete config._isValid;
     } else {
-        return createError(
-            config._i + ' does not match the `ISO 8601` standard',
-            config._d,
-            config._i,
-            config._f
-        );
+        return;
     }
 
     configFromRFC2822(config);
     if (config._isValid === false) {
         delete config._isValid;
     } else {
-        return createError(
-            config._i + ' does not match the `RFC 2822` standard',
-            config._d,
-            config._i,
-            config._f
-        );
+        return;
     }
 
     if (config._strict) {
@@ -261,12 +245,6 @@ export function configFromString(config) {
     } else {
         // Final attempt, use Input Fallback
         hooks.createFromInputFallback(config);
-        createError(
-            config._i + ' failed to build a Date using `new Date()`',
-            config._d,
-            config._i,
-            config._f
-        );
     }
 }
 
index 5be63a2681e8bcaab0166b21f246e22ebce9b2b4..b86de8b92b06be58bb307f14264e6d154a5c8632 100644 (file)
@@ -1,7 +1,6 @@
 import { hooks } from '../utils/hooks';
 import isUndefined from '../utils/is-undefined';
 import getParsingFlags from '../create/parsing-flags';
-import createError from '../utils/create-error';
 
 // Plugins that add properties should also add the key here (null value),
 // so we can properly clone ourselves.
@@ -64,7 +63,6 @@ export function Moment(config) {
     this._d = new Date(config._d != null ? config._d.getTime() : NaN);
     if (!this.isValid()) {
         this._d = new Date(NaN);
-        createError('invalid moment instance', config._d, config._i, config._f);
     }
     // Prevent infinite loop in case updateOffset creates new moment
     // objects.
diff --git a/src/lib/utils/create-error.js b/src/lib/utils/create-error.js
deleted file mode 100644 (file)
index 9c50329..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-import { hooks } from './hooks';
-import isDate from './is-date';
-
-/**
- * Update an Error with the specified date, input and format.
- *
- * @param {*} message The error message
- * @param {*} date The date
- * @param {*} input The input
- * @param {*} format The format
- */
-function makeError(message, date, input, format) {
-    var error = new Error(message);
-    error.date = date;
-    error.input = input;
-    error.format = format;
-    error.toJSON = function toJSON() {
-        return {
-            // Standard
-            message: this.message,
-            name: this.name,
-            // Microsoft
-            description: this.description,
-            number: this.number,
-            // Mozilla
-            fileName: this.fileName,
-            lineNumber: this.lineNumber,
-            columnNumber: this.columnNumber,
-            stack: this.stack,
-        };
-    };
-    return error;
-}
-
-/**
- * Create an Error with the specified message, date, input and format.
- *
- * @param {*} message The error message
- * @param {*} date The date
- * @param {*} input The input
- * @param {*} format The format
- */
-export default function createError(message, date, input, format) {
-    if (hooks.suppressCreateError !== false) {
-        return;
-    }
-    if (isDate(date) && date.toString() !== 'Invalid Date') {
-        return;
-    }
-    throw makeError(message, date, input, format);
-}
-
-// Specify whether to disable throwing errors, ths default value is `true`
-hooks.suppressCreateError = true;
index b4d46970f9232814b02a84f97a14c544382fbc22..288610b2c6bbc3395151ff43da7f7957af2a9d1d 100644 (file)
@@ -2917,34 +2917,3 @@ test('k, kk', function (assert) {
         }
     }
 });
-
-test('Invalid date will throw an error', function (assert) {
-    var i,
-        data,
-        dataList = [
-            ['10:32:17 027', null],
-            ['20202-02-01', moment.ISO_8601],
-            ['20202-02-01', moment.RFC_2822],
-            ['20202-02-01', []],
-            [new Date(NaN), null],
-        ];
-    moment.suppressCreateError = false;
-    for (i = 0; i < dataList.length; i++) {
-        data = dataList[i];
-        try {
-            moment(data[0], data[1]);
-        } catch (error) {
-            assert.ok(
-                error instanceof Error,
-                'Invalid date returns an instance of Error'
-            );
-            if (error.toJSON) {
-                assert.ok(
-                    error.toJSON instanceof Function,
-                    'Error instance contains toJSON method'
-                );
-            }
-        }
-    }
-    moment.suppressCreateError = true;
-});