const require_built = require('../config/dist/esm/built.cjs');
const require_intl = require('../utils/intl.cjs');

//#region ../react-intlayer/dist/esm/@intlayer/core/dist/esm/formatters/relativeTime.mjs
/**
* Calculate the difference between 2 dates in the given unit.
*/
const diffInUnit = (from, to, unit) => {
	const sec = (to.getTime() - from.getTime()) / 1e3;
	switch (unit) {
		case "second": return sec;
		case "minute": return sec / 60;
		case "hour": return sec / 3600;
		case "day": return sec / 86400;
		case "month": return sec / (30 * 86400);
		case "quarter": return sec / (90 * 86400);
		case "year": return sec / (365 * 86400);
		default: return sec;
	}
};
const relativeTime = (from, to = /* @__PURE__ */ new Date(), options) => {
	const fromDate = new Date(from);
	const toDate = new Date(to);
	const unit = options?.unit ?? "second";
	const value = diffInUnit(fromDate, toDate, unit);
	return new require_intl.CachedIntl.RelativeTimeFormat(options?.locale ?? require_built.built_default?.internationalization?.defaultLocale, options).format(Math.round(value), unit);
};

//#endregion
exports.relativeTime = relativeTime;
//# sourceMappingURL=relativeTime.cjs.map