const require_errors = require('./errors.js');
const require_locale = require('./impl/locale.js');
const require_settings = require('./settings.js');
const require_invalid = require('./impl/invalid.js');
const require_util = require('./impl/util.js');
const require_formatter = require('./impl/formatter.js');
const require_regexParser = require('./impl/regexParser.js');
const require_datetime = require('./datetime.js');

//#region ../../node_modules/.pnpm/luxon@3.5.0/node_modules/luxon/src/duration.js
const INVALID = "Invalid Duration";
const lowOrderMatrix = {
	weeks: {
		days: 7,
		hours: 168,
		minutes: 10080,
		seconds: 10080 * 60,
		milliseconds: 10080 * 60 * 1e3
	},
	days: {
		hours: 24,
		minutes: 1440,
		seconds: 1440 * 60,
		milliseconds: 1440 * 60 * 1e3
	},
	hours: {
		minutes: 60,
		seconds: 3600,
		milliseconds: 3600 * 1e3
	},
	minutes: {
		seconds: 60,
		milliseconds: 60 * 1e3
	},
	seconds: { milliseconds: 1e3 }
};
const 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 * 1e3
	},
	quarters: {
		months: 3,
		weeks: 13,
		days: 91,
		hours: 2184,
		minutes: 2184 * 60,
		seconds: 2184 * 60 * 60,
		milliseconds: 2184 * 60 * 60 * 1e3
	},
	months: {
		weeks: 4,
		days: 30,
		hours: 720,
		minutes: 720 * 60,
		seconds: 720 * 60 * 60,
		milliseconds: 720 * 60 * 60 * 1e3
	},
	...lowOrderMatrix
};
const daysInYearAccurate = 146097 / 400;
const daysInMonthAccurate = 146097 / 4800;
const 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 * 1e3
	},
	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 * 1e3 / 4
	},
	months: {
		weeks: daysInMonthAccurate / 7,
		days: daysInMonthAccurate,
		hours: daysInMonthAccurate * 24,
		minutes: daysInMonthAccurate * 24 * 60,
		seconds: daysInMonthAccurate * 24 * 60 * 60,
		milliseconds: daysInMonthAccurate * 24 * 60 * 60 * 1e3
	},
	...lowOrderMatrix
};
const orderedUnits = [
	"years",
	"quarters",
	"months",
	"weeks",
	"days",
	"hours",
	"minutes",
	"seconds",
	"milliseconds"
];
const reverseUnits = orderedUnits.slice(0).reverse();
function clone(dur, alts, clear = false) {
	return new Duration({
		values: clear ? alts.values : {
			...dur.values,
			...alts.values || {}
		},
		loc: dur.loc.clone(alts.loc),
		conversionAccuracy: alts.conversionAccuracy || dur.conversionAccuracy,
		matrix: alts.matrix || dur.matrix
	});
}
function durationToMillis(matrix, vals) {
	let sum = vals.milliseconds ?? 0;
	for (const unit of reverseUnits.slice(1)) if (vals[unit]) sum += vals[unit] * matrix[unit]["milliseconds"];
	return sum;
}
function normalizeValues(matrix, vals) {
	const factor = durationToMillis(matrix, vals) < 0 ? -1 : 1;
	orderedUnits.reduceRight((previous, current) => {
		if (!require_util.isUndefined(vals[current])) {
			if (previous) {
				const previousVal = vals[previous] * factor;
				const conv = matrix[current][previous];
				const rollUp = Math.floor(previousVal / conv);
				vals[current] += rollUp * factor;
				vals[previous] -= rollUp * conv * factor;
			}
			return current;
		} else return previous;
	}, null);
	orderedUnits.reduce((previous, current) => {
		if (!require_util.isUndefined(vals[current])) {
			if (previous) {
				const fraction = vals[previous] % 1;
				vals[previous] -= fraction;
				vals[current] += fraction * matrix[previous][current];
			}
			return current;
		} else return previous;
	}, null);
}
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.
*
* 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}
*
* There's are more methods documented below. In addition, for more information on subtler topics like internationalization and validity, see the external documentation.
*/
var Duration = class Duration {
	/**
	* @private
	*/
	constructor(config) {
		const accurate = config.conversionAccuracy === "longterm" || false;
		let matrix = accurate ? accurateMatrix : casualMatrix;
		if (config.matrix) matrix = config.matrix;
		/**
		* @access private
		*/
		this.values = config.values;
		/**
		* @access private
		*/
		this.loc = config.loc || require_locale.default.create();
		/**
		* @access private
		*/
		this.conversionAccuracy = accurate ? "longterm" : "casual";
		/**
		* @access private
		*/
		this.invalid = config.invalid || null;
		/**
		* @access private
		*/
		this.matrix = matrix;
		/**
		* @access private
		*/
		this.isLuxonDuration = true;
	}
	/**
	* Create Duration from a number of milliseconds.
	* @param {number} count of milliseconds
	* @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
	* @return {Duration}
	*/
	static fromMillis(count, opts) {
		return Duration.fromObject({ milliseconds: count }, opts);
	}
	/**
	* Create a Duration from a JavaScript object with keys like 'years' and 'hours'.
	* If this object is empty then a zero milliseconds duration is returned.
	* @param {Object} obj - the object to create the DateTime from
	* @param {number} obj.years
	* @param {number} obj.quarters
	* @param {number} obj.months
	* @param {number} obj.weeks
	* @param {number} obj.days
	* @param {number} obj.hours
	* @param {number} obj.minutes
	* @param {number} obj.seconds
	* @param {number} obj.milliseconds
	* @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, opts = {}) {
		if (obj == null || typeof obj !== "object") throw new require_errors.InvalidArgumentError(`Duration.fromObject: argument expected to be an object, got ${obj === null ? "null" : typeof obj}`);
		return new Duration({
			values: require_util.normalizeObject(obj, Duration.normalizeUnit),
			loc: require_locale.default.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 (require_util.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 require_errors.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 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 }
	* @example Duration.fromISO('P5Y3M').toObject() //=> { years: 5, months: 3 }
	* @return {Duration}
	*/
	static fromISO(text, opts) {
		const [parsed] = require_regexParser.parseISODuration(text);
		if (parsed) return Duration.fromObject(parsed, opts);
		else return Duration.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`);
	}
	/**
	* Create a Duration from an ISO 8601 time 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 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 }
	* @example Duration.fromISOTime('T11:00').toObject() //=> { hours: 11, minutes: 0, seconds: 0 }
	* @example Duration.fromISOTime('1100').toObject() //=> { hours: 11, minutes: 0, seconds: 0 }
	* @example Duration.fromISOTime('T1100').toObject() //=> { hours: 11, minutes: 0, seconds: 0 }
	* @return {Duration}
	*/
	static fromISOTime(text, opts) {
		const [parsed] = require_regexParser.parseISOTimeOnly(text);
		if (parsed) return Duration.fromObject(parsed, opts);
		else return Duration.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`);
	}
	/**
	* Create an invalid Duration.
	* @param {string} reason - simple string of why this datetime is invalid. Should not contain parameters or anything else data-dependent
	* @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information
	* @return {Duration}
	*/
	static invalid(reason, explanation = null) {
		if (!reason) throw new require_errors.InvalidArgumentError("need to specify a reason the Duration is invalid");
		const invalid = reason instanceof require_invalid.default ? reason : new require_invalid.default(reason, explanation);
		if (require_settings.default.throwOnInvalid) throw new require_errors.InvalidDurationError(invalid);
		else return new Duration({ invalid });
	}
	/**
	* @private
	*/
	static normalizeUnit(unit) {
		const normalized = {
			year: "years",
			years: "years",
			quarter: "quarters",
			quarters: "quarters",
			month: "months",
			months: "months",
			week: "weeks",
			weeks: "weeks",
			day: "days",
			days: "days",
			hour: "hours",
			hours: "hours",
			minute: "minutes",
			minutes: "minutes",
			second: "seconds",
			seconds: "seconds",
			millisecond: "milliseconds",
			milliseconds: "milliseconds"
		}[unit ? unit.toLowerCase() : unit];
		if (!normalized) throw new require_errors.InvalidUnitError(unit);
		return normalized;
	}
	/**
	* Check if an object is a Duration. Works across context boundaries
	* @param {object} o
	* @return {boolean}
	*/
	static isDuration(o) {
		return o && o.isLuxonDuration || false;
	}
	/**
	* Get  the locale of a Duration, such 'en-GB'
	* @type {string}
	*/
	get locale() {
		return this.isValid ? this.loc.locale : null;
	}
	/**
	* Get the numbering system of a Duration, such 'beng'. The numbering system is used when formatting the Duration
	*
	* @type {string}
	*/
	get numberingSystem() {
		return this.isValid ? this.loc.numberingSystem : null;
	}
	/**
	* Returns a string representation of this Duration formatted according to the specified format string. You may use these tokens:
	* * `S` for milliseconds
	* * `s` for seconds
	* * `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
	* * 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
	* @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("y d s") //=> "1 6 2"
	* @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("yy dd sss") //=> "01 06 002"
	* @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("M S") //=> "12 518402000"
	* @return {string}
	*/
	toFormat(fmt, opts = {}) {
		const fmtOpts = {
			...opts,
			floor: opts.round !== false && opts.floor !== false
		};
		return this.isValid ? require_formatter.default.create(this.loc, fmtOpts).formatDurationFromString(this, fmt) : INVALID;
	}
	/**
	* Returns a string representation of a Duration with all units included.
	* To modify its behavior, use `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/NumberFormat#options
	* @param {Object} opts - Formatting options. Accepts the same keys as the options parameter of the native `Intl.NumberFormat` constructor, as well as `listStyle`.
	* @param {string} [opts.listStyle='narrow'] - How to format the merged list. Corresponds to the `style` property of the options parameter of the native `Intl.ListFormat` constructor.
	* @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 = {}) {
		if (!this.isValid) return INVALID;
		const l = orderedUnits.map((unit) => {
			const val = this.values[unit];
			if (require_util.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.
	* @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toObject() //=> { years: 1, days: 6, seconds: 2 }
	* @return {Object}
	*/
	toObject() {
		if (!this.isValid) return {};
		return { ...this.values };
	}
	/**
	* Returns an ISO 8601-compliant string representation of this Duration.
	* @see https://en.wikipedia.org/wiki/ISO_8601#Durations
	* @example Duration.fromObject({ years: 3, seconds: 45 }).toISO() //=> 'P3YT45S'
	* @example Duration.fromObject({ months: 4, seconds: 45 }).toISO() //=> 'P4MT45S'
	* @example Duration.fromObject({ months: 5 }).toISO() //=> 'P5M'
	* @example Duration.fromObject({ minutes: 5 }).toISO() //=> 'PT5M'
	* @example Duration.fromObject({ milliseconds: 6 }).toISO() //=> 'PT0.006S'
	* @return {string}
	*/
	toISO() {
		if (!this.isValid) return null;
		let s = "P";
		if (this.years !== 0) s += this.years + "Y";
		if (this.months !== 0 || this.quarters !== 0) s += this.months + this.quarters * 3 + "M";
		if (this.weeks !== 0) s += this.weeks + "W";
		if (this.days !== 0) s += this.days + "D";
		if (this.hours !== 0 || this.minutes !== 0 || this.seconds !== 0 || this.milliseconds !== 0) s += "T";
		if (this.hours !== 0) s += this.hours + "H";
		if (this.minutes !== 0) s += this.minutes + "M";
		if (this.seconds !== 0 || this.milliseconds !== 0) s += require_util.roundTo(this.seconds + this.milliseconds / 1e3, 3) + "S";
		if (s === "P") s += "T0S";
		return s;
	}
	/**
	* Returns an ISO 8601-compliant string representation of this Duration, formatted as a time of day.
	* Note that this will return null if the duration is invalid, negative, or equal to or greater than 24 hours.
	* @see https://en.wikipedia.org/wiki/ISO_8601#Times
	* @param {Object} opts - options
	* @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0
	* @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0
	* @param {boolean} [opts.includePrefix=false] - include the `T` prefix
	* @param {string} [opts.format='extended'] - choose between the basic and extended format
	* @example Duration.fromObject({ hours: 11 }).toISOTime() //=> '11:00:00.000'
	* @example Duration.fromObject({ hours: 11 }).toISOTime({ suppressMilliseconds: true }) //=> '11:00:00'
	* @example Duration.fromObject({ hours: 11 }).toISOTime({ suppressSeconds: true }) //=> '11:00'
	* @example Duration.fromObject({ hours: 11 }).toISOTime({ includePrefix: true }) //=> 'T11:00:00.000'
	* @example Duration.fromObject({ hours: 11 }).toISOTime({ format: 'basic' }) //=> '110000.000'
	* @return {string}
	*/
	toISOTime(opts = {}) {
		if (!this.isValid) return null;
		const millis = this.toMillis();
		if (millis < 0 || millis >= 864e5) return null;
		opts = {
			suppressMilliseconds: false,
			suppressSeconds: false,
			includePrefix: false,
			format: "extended",
			...opts,
			includeOffset: false
		};
		return require_datetime.default.fromMillis(millis, { zone: "UTC" }).toISOTime(opts);
	}
	/**
	* Returns an ISO 8601 representation of this Duration appropriate for use in JSON.
	* @return {string}
	*/
	toJSON() {
		return this.toISO();
	}
	/**
	* Returns an ISO 8601 representation of this Duration appropriate for use in debugging.
	* @return {string}
	*/
	toString() {
		return this.toISO();
	}
	/**
	* Returns a string representation of this Duration appropriate for the REPL.
	* @return {string}
	*/
	[Symbol.for("nodejs.util.inspect.custom")]() {
		if (this.isValid) return `Duration { values: ${JSON.stringify(this.values)} }`;
		else return `Duration { Invalid, reason: ${this.invalidReason} }`;
	}
	/**
	* Returns an milliseconds value of this Duration.
	* @return {number}
	*/
	toMillis() {
		if (!this.isValid) return NaN;
		return durationToMillis(this.matrix, this.values);
	}
	/**
	* Returns an milliseconds value of this Duration. Alias of {@link toMillis}
	* @return {number}
	*/
	valueOf() {
		return this.toMillis();
	}
	/**
	* Make this Duration longer by the specified amount. Return a newly-constructed Duration.
	* @param {Duration|Object|number} duration - The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
	* @return {Duration}
	*/
	plus(duration) {
		if (!this.isValid) return this;
		const dur = Duration.fromDurationLike(duration), result = {};
		for (const k of orderedUnits) if (require_util.hasOwnProperty(dur.values, k) || require_util.hasOwnProperty(this.values, k)) result[k] = dur.get(k) + this.get(k);
		return clone(this, { values: result }, true);
	}
	/**
	* Make this Duration shorter by the specified amount. Return a newly-constructed Duration.
	* @param {Duration|Object|number} duration - The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
	* @return {Duration}
	*/
	minus(duration) {
		if (!this.isValid) return this;
		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 }).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) {
		if (!this.isValid) return this;
		const result = {};
		for (const k of Object.keys(this.values)) result[k] = require_util.asNumber(fn(this.values[k], k));
		return clone(this, { values: result }, true);
	}
	/**
	* Get the value of unit.
	* @param {string} unit - a unit such as 'minute' or 'day'
	* @example Duration.fromObject({years: 2, days: 3}).get('years') //=> 2
	* @example Duration.fromObject({years: 2, days: 3}).get('months') //=> 0
	* @example Duration.fromObject({years: 2, days: 3}).get('days') //=> 3
	* @return {number}
	*/
	get(unit) {
		return this[Duration.normalizeUnit(unit)];
	}
	/**
	* "Set" the values of specified units. Return a newly-constructed Duration.
	* @param {Object} values - a mapping of units to numbers
	* @example dur.set({ years: 2017 })
	* @example dur.set({ hours: 8, minutes: 30 })
	* @return {Duration}
	*/
	set(values) {
		if (!this.isValid) return this;
		const mixed = {
			...this.values,
			...require_util.normalizeObject(values, Duration.normalizeUnit)
		};
		return clone(this, { values: mixed });
	}
	/**
	* "Set" the locale and/or numberingSystem.  Returns a newly-constructed Duration.
	* @example dur.reconfigure({ locale: 'en-GB' })
	* @return {Duration}
	*/
	reconfigure({ locale, numberingSystem, conversionAccuracy, matrix } = {}) {
		const opts = {
			loc: this.loc.clone({
				locale,
				numberingSystem
			}),
			matrix,
			conversionAccuracy
		};
		return clone(this, opts);
	}
	/**
	* Return the length of the duration in the specified unit.
	* @param {string} unit - a unit such as 'minutes' or 'days'
	* @example Duration.fromObject({years: 1}).as('days') //=> 365
	* @example Duration.fromObject({years: 1}).as('months') //=> 12
	* @example Duration.fromObject({hours: 60}).as('days') //=> 2.5
	* @return {number}
	*/
	as(unit) {
		return this.isValid ? this.shiftTo(unit).get(unit) : NaN;
	}
	/**
	* Reduce this Duration to its canonical representation in its current units.
	* Assuming the overall value of the Duration is positive, this means:
	* - excessive values for lower-order units are converted to higher-order units (if possible, see first and second example)
	* - negative lower-order units are converted to higher order units (there must be such a higher order unit, otherwise
	*   the overall value would be negative, see third example)
	* - fractional values for higher-order units are converted to lower-order units (if possible, see fourth example)
	*
	* If the overall value is negative, the result of this method is equivalent to `this.negate().normalize().negate()`.
	* @example Duration.fromObject({ years: 2, days: 5000 }).normalize().toObject() //=> { years: 15, days: 255 }
	* @example Duration.fromObject({ days: 5000 }).normalize().toObject() //=> { days: 5000 }
	* @example Duration.fromObject({ hours: 12, minutes: -45 }).normalize().toObject() //=> { hours: 11, minutes: 15 }
	* @example Duration.fromObject({ years: 2.5, days: 0, hours: 0 }).normalize().toObject() //=> { years: 2, days: 182, hours: 12 }
	* @return {Duration}
	*/
	normalize() {
		if (!this.isValid) return this;
		const vals = this.toObject();
		normalizeValues(this.matrix, vals);
		return clone(this, { values: vals }, true);
	}
	/**
	* 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}
	*/
	shiftTo(...units) {
		if (!this.isValid) return this;
		if (units.length === 0) return this;
		units = units.map((u) => Duration.normalizeUnit(u));
		const built = {}, accumulated = {}, vals = this.toObject();
		let lastUnit;
		for (const k of orderedUnits) if (units.indexOf(k) >= 0) {
			lastUnit = k;
			let own = 0;
			for (const ak in accumulated) {
				own += this.matrix[ak][k] * accumulated[ak];
				accumulated[ak] = 0;
			}
			if (require_util.isNumber(vals[k])) own += vals[k];
			const i = Math.trunc(own);
			built[k] = i;
			accumulated[k] = (own * 1e3 - i * 1e3) / 1e3;
		} else if (require_util.isNumber(vals[k])) accumulated[k] = vals[k];
		for (const key in accumulated) if (accumulated[key] !== 0) built[lastUnit] += key === lastUnit ? accumulated[key] : accumulated[key] / this.matrix[lastUnit][key];
		normalizeValues(this.matrix, built);
		return clone(this, { values: built }, true);
	}
	/**
	* 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}
	*/
	negate() {
		if (!this.isValid) return this;
		const negated = {};
		for (const k of Object.keys(this.values)) negated[k] = this.values[k] === 0 ? 0 : -this.values[k];
		return clone(this, { values: negated }, true);
	}
	/**
	* Get the years.
	* @type {number}
	*/
	get years() {
		return this.isValid ? this.values.years || 0 : NaN;
	}
	/**
	* Get the quarters.
	* @type {number}
	*/
	get quarters() {
		return this.isValid ? this.values.quarters || 0 : NaN;
	}
	/**
	* Get the months.
	* @type {number}
	*/
	get months() {
		return this.isValid ? this.values.months || 0 : NaN;
	}
	/**
	* Get the weeks
	* @type {number}
	*/
	get weeks() {
		return this.isValid ? this.values.weeks || 0 : NaN;
	}
	/**
	* Get the days.
	* @type {number}
	*/
	get days() {
		return this.isValid ? this.values.days || 0 : NaN;
	}
	/**
	* Get the hours.
	* @type {number}
	*/
	get hours() {
		return this.isValid ? this.values.hours || 0 : NaN;
	}
	/**
	* Get the minutes.
	* @type {number}
	*/
	get minutes() {
		return this.isValid ? this.values.minutes || 0 : NaN;
	}
	/**
	* Get the seconds.
	* @return {number}
	*/
	get seconds() {
		return this.isValid ? this.values.seconds || 0 : NaN;
	}
	/**
	* Get the milliseconds.
	* @return {number}
	*/
	get milliseconds() {
		return this.isValid ? this.values.milliseconds || 0 : NaN;
	}
	/**
	* Returns whether the Duration is invalid. Invalid durations are returned by diff operations
	* on invalid DateTimes or Intervals.
	* @return {boolean}
	*/
	get isValid() {
		return this.invalid === null;
	}
	/**
	* Returns an error code if this Duration became invalid, or null if the Duration is valid
	* @return {string}
	*/
	get invalidReason() {
		return this.invalid ? this.invalid.reason : null;
	}
	/**
	* Returns an explanation of why this Duration became invalid, or null if the Duration is valid
	* @type {string}
	*/
	get invalidExplanation() {
		return this.invalid ? this.invalid.explanation : null;
	}
	/**
	* Equality check
	* Two Durations are equal iff they have the same units and the same values for each unit.
	* @param {Duration} other
	* @return {boolean}
	*/
	equals(other) {
		if (!this.isValid || !other.isValid) return false;
		if (!this.loc.equals(other.loc)) return false;
		function eq(v1, v2) {
			if (v1 === void 0 || v1 === 0) return v2 === void 0 || v2 === 0;
			return v1 === v2;
		}
		for (const u of orderedUnits) if (!eq(this.values[u], other.values[u])) return false;
		return true;
	}
};

//#endregion
exports.default = Duration;