aboutsummaryrefslogtreecommitdiffstats
path: root/npm_assets/node_modules/luxon/src/duration.js
diff options
context:
space:
mode:
Diffstat (limited to 'npm_assets/node_modules/luxon/src/duration.js')
-rw-r--r--npm_assets/node_modules/luxon/src/duration.js376
1 files changed, 222 insertions, 154 deletions
diff --git a/npm_assets/node_modules/luxon/src/duration.js b/npm_assets/node_modules/luxon/src/duration.js
index 4fcfa4b..fc512b6 100644
--- a/npm_assets/node_modules/luxon/src/duration.js
+++ b/npm_assets/node_modules/luxon/src/duration.js
@@ -9,97 +9,94 @@ import {
isNumber,
isUndefined,
normalizeObject,
- roundTo
+ roundTo,
} from "./impl/util.js";
import Settings from "./settings.js";
const INVALID = "Invalid Duration";
// unit conversion constants
-const lowOrderMatrix = {
+export const lowOrderMatrix = {
weeks: {
days: 7,
hours: 7 * 24,
minutes: 7 * 24 * 60,
seconds: 7 * 24 * 60 * 60,
- milliseconds: 7 * 24 * 60 * 60 * 1000
+ milliseconds: 7 * 24 * 60 * 60 * 1000,
},
days: {
hours: 24,
minutes: 24 * 60,
seconds: 24 * 60 * 60,
- milliseconds: 24 * 60 * 60 * 1000
+ milliseconds: 24 * 60 * 60 * 1000,
},
hours: { minutes: 60, seconds: 60 * 60, milliseconds: 60 * 60 * 1000 },
minutes: { seconds: 60, milliseconds: 60 * 1000 },
- seconds: { milliseconds: 1000 }
+ seconds: { milliseconds: 1000 },
},
- casualMatrix = Object.assign(
- {
- years: {
- quarters: 4,
- months: 12,
- weeks: 52,
- days: 365,
- hours: 365 * 24,
- minutes: 365 * 24 * 60,
- seconds: 365 * 24 * 60 * 60,
- milliseconds: 365 * 24 * 60 * 60 * 1000
- },
- quarters: {
- months: 3,
- weeks: 13,
- days: 91,
- hours: 91 * 24,
- minutes: 91 * 24 * 60,
- seconds: 91 * 24 * 60 * 60,
- milliseconds: 91 * 24 * 60 * 60 * 1000
- },
- months: {
- weeks: 4,
- days: 30,
- hours: 30 * 24,
- minutes: 30 * 24 * 60,
- seconds: 30 * 24 * 60 * 60,
- milliseconds: 30 * 24 * 60 * 60 * 1000
- }
+ casualMatrix = {
+ years: {
+ quarters: 4,
+ months: 12,
+ weeks: 52,
+ days: 365,
+ hours: 365 * 24,
+ minutes: 365 * 24 * 60,
+ seconds: 365 * 24 * 60 * 60,
+ milliseconds: 365 * 24 * 60 * 60 * 1000,
+ },
+ quarters: {
+ months: 3,
+ weeks: 13,
+ days: 91,
+ hours: 91 * 24,
+ minutes: 91 * 24 * 60,
+ seconds: 91 * 24 * 60 * 60,
+ milliseconds: 91 * 24 * 60 * 60 * 1000,
},
- lowOrderMatrix
- ),
+ months: {
+ weeks: 4,
+ days: 30,
+ hours: 30 * 24,
+ minutes: 30 * 24 * 60,
+ seconds: 30 * 24 * 60 * 60,
+ milliseconds: 30 * 24 * 60 * 60 * 1000,
+ },
+
+ ...lowOrderMatrix,
+ },
daysInYearAccurate = 146097.0 / 400,
daysInMonthAccurate = 146097.0 / 4800,
- accurateMatrix = Object.assign(
- {
- years: {
- quarters: 4,
- months: 12,
- weeks: daysInYearAccurate / 7,
- days: daysInYearAccurate,
- hours: daysInYearAccurate * 24,
- minutes: daysInYearAccurate * 24 * 60,
- seconds: daysInYearAccurate * 24 * 60 * 60,
- milliseconds: daysInYearAccurate * 24 * 60 * 60 * 1000
- },
- quarters: {
- months: 3,
- weeks: daysInYearAccurate / 28,
- days: daysInYearAccurate / 4,
- hours: (daysInYearAccurate * 24) / 4,
- minutes: (daysInYearAccurate * 24 * 60) / 4,
- seconds: (daysInYearAccurate * 24 * 60 * 60) / 4,
- milliseconds: (daysInYearAccurate * 24 * 60 * 60 * 1000) / 4
- },
- months: {
- weeks: daysInMonthAccurate / 7,
- days: daysInMonthAccurate,
- hours: daysInMonthAccurate * 24,
- minutes: daysInMonthAccurate * 24 * 60,
- seconds: daysInMonthAccurate * 24 * 60 * 60,
- milliseconds: daysInMonthAccurate * 24 * 60 * 60 * 1000
- }
+ accurateMatrix = {
+ years: {
+ quarters: 4,
+ months: 12,
+ weeks: daysInYearAccurate / 7,
+ days: daysInYearAccurate,
+ hours: daysInYearAccurate * 24,
+ minutes: daysInYearAccurate * 24 * 60,
+ seconds: daysInYearAccurate * 24 * 60 * 60,
+ milliseconds: daysInYearAccurate * 24 * 60 * 60 * 1000,
+ },
+ quarters: {
+ months: 3,
+ weeks: daysInYearAccurate / 28,
+ days: daysInYearAccurate / 4,
+ hours: (daysInYearAccurate * 24) / 4,
+ minutes: (daysInYearAccurate * 24 * 60) / 4,
+ seconds: (daysInYearAccurate * 24 * 60 * 60) / 4,
+ milliseconds: (daysInYearAccurate * 24 * 60 * 60 * 1000) / 4,
+ },
+ months: {
+ weeks: daysInMonthAccurate / 7,
+ days: daysInMonthAccurate,
+ hours: daysInMonthAccurate * 24,
+ minutes: daysInMonthAccurate * 24 * 60,
+ seconds: daysInMonthAccurate * 24 * 60 * 60,
+ milliseconds: daysInMonthAccurate * 24 * 60 * 60 * 1000,
},
- lowOrderMatrix
- );
+ ...lowOrderMatrix,
+ };
// units ordered by size
const orderedUnits = [
@@ -111,7 +108,7 @@ const orderedUnits = [
"hours",
"minutes",
"seconds",
- "milliseconds"
+ "milliseconds",
];
const reverseUnits = orderedUnits.slice(0).reverse();
@@ -120,9 +117,10 @@ const reverseUnits = orderedUnits.slice(0).reverse();
function clone(dur, alts, clear = false) {
// deep merge for vals
const conf = {
- values: clear ? alts.values : Object.assign({}, dur.values, alts.values || {}),
+ values: clear ? alts.values : { ...dur.values, ...(alts.values || {}) },
loc: dur.loc.clone(alts.loc),
- conversionAccuracy: alts.conversionAccuracy || dur.conversionAccuracy
+ conversionAccuracy: alts.conversionAccuracy || dur.conversionAccuracy,
+ matrix: alts.matrix || dur.matrix,
};
return new Duration(conf);
}
@@ -157,16 +155,27 @@ function normalizeValues(matrix, vals) {
}, null);
}
+// Remove all properties with a value of 0 from an object
+function removeZeroes(vals) {
+ const newVals = {};
+ for (const [key, value] of Object.entries(vals)) {
+ if (value !== 0) {
+ newVals[key] = value;
+ }
+ }
+ return newVals;
+}
+
/**
- * A Duration object represents a period of time, like "2 months" or "1 day, 1 hour". Conceptually, it's just a map of units to their quantities, accompanied by some additional configuration and methods for creating, parsing, interrogating, transforming, and formatting them. They can be used on their own or in conjunction with other Luxon types; for example, you can use {@link DateTime.plus} to add a Duration object to a DateTime, producing another DateTime.
+ * A Duration object represents a period of time, like "2 months" or "1 day, 1 hour". Conceptually, it's just a map of units to their quantities, accompanied by some additional configuration and methods for creating, parsing, interrogating, transforming, and formatting them. They can be used on their own or in conjunction with other Luxon types; for example, you can use {@link DateTime#plus} to add a Duration object to a DateTime, producing another DateTime.
*
* Here is a brief overview of commonly used methods and getters in Duration:
*
* * **Creation** To create a Duration, use {@link Duration.fromMillis}, {@link Duration.fromObject}, or {@link Duration.fromISO}.
- * * **Unit values** See the {@link Duration.years}, {@link Duration.months}, {@link Duration.weeks}, {@link Duration.days}, {@link Duration.hours}, {@link Duration.minutes}, {@link Duration.seconds}, {@link Duration.milliseconds} accessors.
- * * **Configuration** See {@link Duration.locale} and {@link Duration.numberingSystem} accessors.
- * * **Transformation** To create new Durations out of old ones use {@link Duration.plus}, {@link Duration.minus}, {@link Duration.normalize}, {@link Duration.set}, {@link Duration.reconfigure}, {@link Duration.shiftTo}, and {@link Duration.negate}.
- * * **Output** To convert the Duration into other representations, see {@link Duration.as}, {@link Duration.toISO}, {@link Duration.toFormat}, and {@link Duration.toJSON}
+ * * **Unit values** See the {@link Duration#years}, {@link Duration#months}, {@link Duration#weeks}, {@link Duration#days}, {@link Duration#hours}, {@link Duration#minutes}, {@link Duration#seconds}, {@link Duration#milliseconds} accessors.
+ * * **Configuration** See {@link Duration#locale} and {@link Duration#numberingSystem} accessors.
+ * * **Transformation** To create new Durations out of old ones use {@link Duration#plus}, {@link Duration#minus}, {@link Duration#normalize}, {@link Duration#set}, {@link Duration#reconfigure}, {@link Duration#shiftTo}, and {@link Duration#negate}.
+ * * **Output** To convert the Duration into other representations, see {@link Duration#as}, {@link Duration#toISO}, {@link Duration#toFormat}, and {@link Duration#toJSON}
*
* There's are more methods documented below. In addition, for more information on subtler topics like internationalization and validity, see the external documentation.
*/
@@ -176,6 +185,12 @@ export default class Duration {
*/
constructor(config) {
const accurate = config.conversionAccuracy === "longterm" || false;
+ let matrix = accurate ? accurateMatrix : casualMatrix;
+
+ if (config.matrix) {
+ matrix = config.matrix;
+ }
+
/**
* @access private
*/
@@ -195,7 +210,7 @@ export default class Duration {
/**
* @access private
*/
- this.matrix = accurate ? accurateMatrix : casualMatrix;
+ this.matrix = matrix;
/**
* @access private
*/
@@ -212,7 +227,7 @@ export default class Duration {
* @return {Duration}
*/
static fromMillis(count, opts) {
- return Duration.fromObject(Object.assign({ milliseconds: count }, opts));
+ return Duration.fromObject({ milliseconds: count }, opts);
}
/**
@@ -228,12 +243,14 @@ export default class Duration {
* @param {number} obj.minutes
* @param {number} obj.seconds
* @param {number} obj.milliseconds
- * @param {string} [obj.locale='en-US'] - the locale to use
- * @param {string} obj.numberingSystem - the numbering system to use
- * @param {string} [obj.conversionAccuracy='casual'] - the conversion system to use
+ * @param {Object} [opts=[]] - options for creating this Duration
+ * @param {string} [opts.locale='en-US'] - the locale to use
+ * @param {string} opts.numberingSystem - the numbering system to use
+ * @param {string} [opts.conversionAccuracy='casual'] - the preset conversion system to use
+ * @param {string} [opts.matrix=Object] - the custom conversion system to use
* @return {Duration}
*/
- static fromObject(obj) {
+ static fromObject(obj, opts = {}) {
if (obj == null || typeof obj !== "object") {
throw new InvalidArgumentError(
`Duration.fromObject: argument expected to be an object, got ${
@@ -241,25 +258,47 @@ export default class Duration {
}`
);
}
+
return new Duration({
- values: normalizeObject(obj, Duration.normalizeUnit, [
- "locale",
- "numberingSystem",
- "conversionAccuracy",
- "zone" // a bit of debt; it's super inconvenient internally not to be able to blindly pass this
- ]),
- loc: Locale.fromObject(obj),
- conversionAccuracy: obj.conversionAccuracy
+ values: normalizeObject(obj, Duration.normalizeUnit),
+ loc: Locale.fromObject(opts),
+ conversionAccuracy: opts.conversionAccuracy,
+ matrix: opts.matrix,
});
}
/**
+ * Create a Duration from DurationLike.
+ *
+ * @param {Object | number | Duration} durationLike
+ * One of:
+ * - object with keys like 'years' and 'hours'.
+ * - number representing milliseconds
+ * - Duration instance
+ * @return {Duration}
+ */
+ static fromDurationLike(durationLike) {
+ if (isNumber(durationLike)) {
+ return Duration.fromMillis(durationLike);
+ } else if (Duration.isDuration(durationLike)) {
+ return durationLike;
+ } else if (typeof durationLike === "object") {
+ return Duration.fromObject(durationLike);
+ } else {
+ throw new InvalidArgumentError(
+ `Unknown duration argument ${durationLike} of type ${typeof durationLike}`
+ );
+ }
+ }
+
+ /**
* Create a Duration from an ISO 8601 duration string.
* @param {string} text - text to parse
* @param {Object} opts - options for parsing
* @param {string} [opts.locale='en-US'] - the locale to use
* @param {string} opts.numberingSystem - the numbering system to use
- * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
+ * @param {string} [opts.conversionAccuracy='casual'] - the preset conversion system to use
+ * @param {string} [opts.matrix=Object] - the preset conversion system to use
* @see https://en.wikipedia.org/wiki/ISO_8601#Durations
* @example Duration.fromISO('P3Y6M1W4DT12H30M5S').toObject() //=> { years: 3, months: 6, weeks: 1, days: 4, hours: 12, minutes: 30, seconds: 5 }
* @example Duration.fromISO('PT23H').toObject() //=> { hours: 23 }
@@ -269,8 +308,7 @@ export default class Duration {
static fromISO(text, opts) {
const [parsed] = parseISODuration(text);
if (parsed) {
- const obj = Object.assign(parsed, opts);
- return Duration.fromObject(obj);
+ return Duration.fromObject(parsed, opts);
} else {
return Duration.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`);
}
@@ -282,7 +320,8 @@ export default class Duration {
* @param {Object} opts - options for parsing
* @param {string} [opts.locale='en-US'] - the locale to use
* @param {string} opts.numberingSystem - the numbering system to use
- * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
+ * @param {string} [opts.conversionAccuracy='casual'] - the preset conversion system to use
+ * @param {string} [opts.matrix=Object] - the conversion system to use
* @see https://en.wikipedia.org/wiki/ISO_8601#Times
* @example Duration.fromISOTime('11:22:33.444').toObject() //=> { hours: 11, minutes: 22, seconds: 33, milliseconds: 444 }
* @example Duration.fromISOTime('11:00').toObject() //=> { hours: 11, minutes: 0, seconds: 0 }
@@ -294,8 +333,7 @@ export default class Duration {
static fromISOTime(text, opts) {
const [parsed] = parseISOTimeOnly(text);
if (parsed) {
- const obj = Object.assign(parsed, opts);
- return Duration.fromObject(obj);
+ return Duration.fromObject(parsed, opts);
} else {
return Duration.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`);
}
@@ -343,7 +381,7 @@ export default class Duration {
second: "seconds",
seconds: "seconds",
millisecond: "milliseconds",
- milliseconds: "milliseconds"
+ milliseconds: "milliseconds",
}[unit ? unit.toLowerCase() : unit];
if (!normalized) throw new InvalidUnitError(unit);
@@ -384,11 +422,13 @@ export default class Duration {
* * `m` for minutes
* * `h` for hours
* * `d` for days
+ * * `w` for weeks
* * `M` for months
* * `y` for years
* Notes:
* * Add padding by repeating the token, e.g. "yy" pads the years to two digits, "hhhh" pads the hours out to four digits
- * * The duration will be converted to the set of units in the format string using {@link Duration.shiftTo} and the Durations's conversion accuracy setting.
+ * * Tokens can be escaped by wrapping with single quotes.
+ * * The duration will be converted to the set of units in the format string using {@link Duration#shiftTo} and the Durations's conversion accuracy setting.
* @param {string} fmt - the format string
* @param {Object} opts - options
* @param {boolean} [opts.floor=true] - floor numerical values
@@ -399,32 +439,54 @@ export default class Duration {
*/
toFormat(fmt, opts = {}) {
// reverse-compat since 1.2; we always round down now, never up, and we do it by default
- const fmtOpts = Object.assign({}, opts, {
- floor: opts.round !== false && opts.floor !== false
- });
+ const fmtOpts = {
+ ...opts,
+ floor: opts.round !== false && opts.floor !== false,
+ };
return this.isValid
? Formatter.create(this.loc, fmtOpts).formatDurationFromString(this, fmt)
: INVALID;
}
/**
+ * Returns a string representation of a Duration with all units included.
+ * To modify its behavior use the `listStyle` and any Intl.NumberFormat option, though `unitDisplay` is especially relevant.
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
+ * @param opts - On option object to override the formatting. Accepts the same keys as the options parameter of the native `Int.NumberFormat` constructor, as well as `listStyle`.
+ * @example
+ * ```js
+ * var dur = Duration.fromObject({ days: 1, hours: 5, minutes: 6 })
+ * dur.toHuman() //=> '1 day, 5 hours, 6 minutes'
+ * dur.toHuman({ listStyle: "long" }) //=> '1 day, 5 hours, and 6 minutes'
+ * dur.toHuman({ unitDisplay: "short" }) //=> '1 day, 5 hr, 6 min'
+ * ```
+ */
+ toHuman(opts = {}) {
+ const l = orderedUnits
+ .map((unit) => {
+ const val = this.values[unit];
+ if (isUndefined(val)) {
+ return null;
+ }
+ return this.loc
+ .numberFormatter({ style: "unit", unitDisplay: "long", ...opts, unit: unit.slice(0, -1) })
+ .format(val);
+ })
+ .filter((n) => n);
+
+ return this.loc
+ .listFormatter({ type: "conjunction", style: opts.listStyle || "narrow", ...opts })
+ .format(l);
+ }
+
+ /**
* Returns a JavaScript object with this Duration's values.
- * @param opts - options for generating the object
- * @param {boolean} [opts.includeConfig=false] - include configuration attributes in the output
* @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toObject() //=> { years: 1, days: 6, seconds: 2 }
* @return {Object}
*/
- toObject(opts = {}) {
+ toObject() {
if (!this.isValid) return {};
-
- const base = Object.assign({}, this.values);
-
- if (opts.includeConfig) {
- base.conversionAccuracy = this.conversionAccuracy;
- base.numberingSystem = this.loc.numberingSystem;
- base.locale = this.loc.locale;
- }
- return base;
+ return { ...this.values };
}
/**
@@ -480,15 +542,13 @@ export default class Duration {
const millis = this.toMillis();
if (millis < 0 || millis >= 86400000) return null;
- opts = Object.assign(
- {
- suppressMilliseconds: false,
- suppressSeconds: false,
- includePrefix: false,
- format: "extended"
- },
- opts
- );
+ opts = {
+ suppressMilliseconds: false,
+ suppressSeconds: false,
+ includePrefix: false,
+ format: "extended",
+ ...opts,
+ };
const value = this.shiftTo("hours", "minutes", "seconds", "milliseconds");
@@ -550,7 +610,7 @@ export default class Duration {
plus(duration) {
if (!this.isValid) return this;
- const dur = friendlyDuration(duration),
+ const dur = Duration.fromDurationLike(duration),
result = {};
for (const k of orderedUnits) {
@@ -570,15 +630,15 @@ export default class Duration {
minus(duration) {
if (!this.isValid) return this;
- const dur = friendlyDuration(duration);
+ const dur = Duration.fromDurationLike(duration);
return this.plus(dur.negate());
}
/**
* Scale this Duration by the specified amount. Return a newly-constructed Duration.
* @param {function} fn - The function to apply to each unit. Arity is 1 or 2: the value of the unit and, optionally, the unit name. Must return a number.
- * @example Duration.fromObject({ hours: 1, minutes: 30 }).mapUnit(x => x * 2) //=> { hours: 2, minutes: 60 }
- * @example Duration.fromObject({ hours: 1, minutes: 30 }).mapUnit((x, u) => u === "hour" ? x * 2 : x) //=> { hours: 2, minutes: 30 }
+ * @example Duration.fromObject({ hours: 1, minutes: 30 }).mapUnits(x => x * 2) //=> { hours: 2, minutes: 60 }
+ * @example Duration.fromObject({ hours: 1, minutes: 30 }).mapUnits((x, u) => u === "hours" ? x * 2 : x) //=> { hours: 2, minutes: 30 }
* @return {Duration}
*/
mapUnits(fn) {
@@ -612,7 +672,7 @@ export default class Duration {
set(values) {
if (!this.isValid) return this;
- const mixed = Object.assign(this.values, normalizeObject(values, Duration.normalizeUnit, []));
+ const mixed = { ...this.values, ...normalizeObject(values, Duration.normalizeUnit) };
return clone(this, { values: mixed });
}
@@ -621,14 +681,9 @@ export default class Duration {
* @example dur.reconfigure({ locale: 'en-GB' })
* @return {Duration}
*/
- reconfigure({ locale, numberingSystem, conversionAccuracy } = {}) {
- const loc = this.loc.clone({ locale, numberingSystem }),
- opts = { loc };
-
- if (conversionAccuracy) {
- opts.conversionAccuracy = conversionAccuracy;
- }
-
+ reconfigure({ locale, numberingSystem, conversionAccuracy, matrix } = {}) {
+ const loc = this.loc.clone({ locale, numberingSystem });
+ const opts = { loc, matrix, conversionAccuracy };
return clone(this, opts);
}
@@ -658,6 +713,17 @@ export default class Duration {
}
/**
+ * Rescale units to its largest representation
+ * @example Duration.fromObject({ milliseconds: 90000 }).rescale().toObject() //=> { minutes: 1, seconds: 30 }
+ * @return {Duration}
+ */
+ rescale() {
+ if (!this.isValid) return this;
+ const vals = removeZeroes(this.normalize().shiftToAll().toObject());
+ return clone(this, { values: vals }, true);
+ }
+
+ /**
* Convert this Duration into its representation in a different set of units.
* @example Duration.fromObject({ hours: 1, seconds: 30 }).shiftTo('minutes', 'milliseconds').toObject() //=> { minutes: 60, milliseconds: 30000 }
* @return {Duration}
@@ -669,7 +735,7 @@ export default class Duration {
return this;
}
- units = units.map(u => Duration.normalizeUnit(u));
+ units = units.map((u) => Duration.normalizeUnit(u));
const built = {},
accumulated = {},
@@ -695,7 +761,7 @@ export default class Duration {
const i = Math.trunc(own);
built[k] = i;
- accumulated[k] = own - i; // we'd like to absorb these fractions in another unit
+ accumulated[k] = (own * 1000 - i * 1000) / 1000;
// plus anything further down the chain that should be rolled up in to this
for (const down in vals) {
@@ -722,6 +788,25 @@ export default class Duration {
}
/**
+ * Shift this Duration to all available units.
+ * Same as shiftTo("years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds")
+ * @return {Duration}
+ */
+ shiftToAll() {
+ if (!this.isValid) return this;
+ return this.shiftTo(
+ "years",
+ "months",
+ "weeks",
+ "days",
+ "hours",
+ "minutes",
+ "seconds",
+ "milliseconds"
+ );
+ }
+
+ /**
* Return the negative of this Duration.
* @example Duration.fromObject({ hours: 1, seconds: 30 }).negate().toObject() //=> { hours: -1, seconds: -30 }
* @return {Duration}
@@ -730,7 +815,7 @@ export default class Duration {
if (!this.isValid) return this;
const negated = {};
for (const k of Object.keys(this.values)) {
- negated[k] = -this.values[k];
+ negated[k] = this.values[k] === 0 ? 0 : -this.values[k];
}
return clone(this, { values: negated }, true);
}
@@ -861,20 +946,3 @@ export default class Duration {
return true;
}
}
-
-/**
- * @private
- */
-export function friendlyDuration(durationish) {
- if (isNumber(durationish)) {
- return Duration.fromMillis(durationish);
- } else if (Duration.isDuration(durationish)) {
- return durationish;
- } else if (typeof durationish === "object") {
- return Duration.fromObject(durationish);
- } else {
- throw new InvalidArgumentError(
- `Unknown duration argument ${durationish} of type ${typeof durationish}`
- );
- }
-}