//#region src/shared/timeSeries.ts
var e = 1440 * 60 * 1e3;
function t(e) {
	return new Date(Date.UTC(e.getUTCFullYear(), e.getUTCMonth(), e.getUTCDate()));
}
function n(e) {
	let n = new Date(e);
	if (Number.isNaN(n.getTime())) throw Error(`Invalid ISO datetime: ${e}`);
	return t(n).toISOString().slice(0, 10);
}
function r(n, r) {
	let i = t(new Date(n)), a = t(new Date(r));
	if (Number.isNaN(i.getTime())) throw Error(`Invalid "from" datetime: ${n}`);
	if (Number.isNaN(a.getTime())) throw Error(`Invalid "to" datetime: ${r}`);
	if (i.getTime() > a.getTime()) throw Error(`"from" must be before or equal to "to": ${n} > ${r}`);
	let o = [];
	for (let t = i.getTime(); t <= a.getTime(); t += e) o.push(new Date(t).toISOString().slice(0, 10));
	return o;
}
function i(e, t) {
	let r = /* @__PURE__ */ new Map();
	for (let i of e) if (t.includes(i.category)) {
		let e = `${n(i.day)}|${i.category}`, t = r.get(e) ?? 0;
		r.set(e, t + i.value);
	}
	return r;
}
function a(e) {
	let t = r(e.fromIsoDateTime, e.toIsoDateTime), n = i(e.buckets, e.categories);
	return e.categories.map((e) => ({
		id: e,
		data: t.map((t) => ({
			x: t,
			y: n.get(`${t}|${e}`) ?? 0
		}))
	}));
}
//#endregion
export { i as aggregateValuesByDayAndCategory, r as buildUtcDayRange, a as toUtcDailyCategorySeries, n as toUtcDayKey };

//# sourceMappingURL=timeSeries.js.map