jtc-utils
Version:
Utilities for Japanese Traditional Companies
24 lines • 819 B
JavaScript
import { getTimeZone } from "./getTimeZone.js";
export function getTimeZoneOffset(date, tz) {
const tzDate = relativeTime(date, tz);
const zDate = relativeTime(date, getTimeZone());
return zDate.getTime() - tzDate.getTime();
}
function relativeTime(date, timeZone) {
const parts = {};
const format = new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
timeZone,
hourCycle: "h23",
});
for (const part of format.formatToParts(date)) {
parts[part.type] = part.value;
}
return new Date(`${parts.year}-${parts.month}-${parts.day}T${parts.hour}:${parts.minute}:${parts.second}Z`);
}
//# sourceMappingURL=getTimeZoneOffset.js.map