Files
klz-cables.com/.pnpm-store/v10/files/7c/f5ea7b43ac5c08998f6ec099f02aa4d347cc6b7ef1590449487ea2e3b0f6e5850ab6c9ad4e50ef5e6c61d1e29a6454e8ea14cd9711138537650a01b814720c
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

41 lines
1.5 KiB
Plaintext

const offsetFormatCache = {};
const offsetCache = {};
/**
* The function extracts UTC offset in minutes from the given date in specified
* time zone.
*
* Unlike `Date.prototype.getTimezoneOffset`, this function returns the value
* mirrored to the sign of the offset in the time zone. For Asia/Singapore
* (UTC+8), `tzOffset` returns 480, while `getTimezoneOffset` returns -480.
*
* @param timeZone - Time zone name (IANA or UTC offset)
* @param date - Date to check the offset for
*
* @returns UTC offset in minutes
*/
export function tzOffset(timeZone, date) {
try {
const format = offsetFormatCache[timeZone] ||= new Intl.DateTimeFormat("en-GB", {
timeZone,
hour: "numeric",
timeZoneName: "longOffset"
}).format;
const offsetStr = format(date).split('GMT')[1] || '';
if (offsetStr in offsetCache) return offsetCache[offsetStr];
return calcOffset(offsetStr, offsetStr.split(":"));
} catch {
// Fallback to manual parsing if the runtime doesn't support ±HH:MM/±HHMM/±HH
// See: https://github.com/nodejs/node/issues/53419
if (timeZone in offsetCache) return offsetCache[timeZone];
const captures = timeZone?.match(offsetRe);
if (captures) return calcOffset(timeZone, captures.slice(1));
return NaN;
}
}
const offsetRe = /([+-]\d\d):?(\d\d)?/;
function calcOffset(cacheStr, values) {
const hours = +values[0];
const minutes = +(values[1] || 0);
return offsetCache[cacheStr] = hours > 0 ? hours * 60 + minutes : hours * 60 - minutes;
}