UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

41 lines (40 loc) 1.83 kB
import { o as asDateTimestampMs } from "./number-coercion-CLj0HTDM.js"; import { a as parseIsoCalendarTimeMs, r as isOffsetlessIsoDateTime, t as getUtcCalendarTimeMs } from "./iso-time-C2akJNwm.js"; //#region src/infra/format-time/parse-offsetless-zoned-datetime.ts function parseOffsetlessIsoDateTimeInTimeZone(raw, timeZone) { const naiveMs = isOffsetlessIsoDateTime(raw) ? parseIsoCalendarTimeMs(raw) : void 0; if (naiveMs === void 0) return null; try { const matchingInstants = [ -864e5, 0, 864e5 ].map((shiftMs) => asDateTimestampMs(naiveMs + shiftMs)).filter((probeMs) => probeMs !== void 0).map((probeMs) => naiveMs - (getZonedWallTimeMs(probeMs, timeZone) - probeMs)).filter((candidateMs) => asDateTimestampMs(candidateMs) !== void 0 && getZonedWallTimeMs(candidateMs, timeZone) === naiveMs); return matchingInstants.length > 0 ? new Date(Math.min(...matchingInstants)).toISOString() : null; } catch { return null; } } function getZonedWallTimeMs(utcMs, timeZone) { const utcDate = new Date(utcMs); const parts = new Intl.DateTimeFormat("en-US", { timeZone, era: "short", year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23" }).formatToParts(utcDate); const getNumericPart = (type) => { const part = parts.find((candidate) => candidate.type === type); return Number.parseInt(part?.value ?? "0", 10); }; const eraYear = getNumericPart("year"); const year = parts.find((part) => part.type === "era")?.value === "BC" ? 1 - eraYear : eraYear; return getUtcCalendarTimeMs(year, getNumericPart("month") - 1, getNumericPart("day"), getNumericPart("hour"), getNumericPart("minute"), getNumericPart("second"), utcDate.getUTCMilliseconds()); } //#endregion export { parseOffsetlessIsoDateTimeInTimeZone as t };