UNPKG

@adyen/adyen-platform-experience-web

Version:

![Platform Experience header](https://github.com/Adyen/adyen-platform-experience-web/assets/7926613/18094965-9e01-450e-8dc9-ea84e6b22c2b)

29 lines (28 loc) 1.64 kB
import { useMemo as c, useRef as d, useState as g } from "../../../../external/preact/hooks/dist/hooks.module.js"; import { getTimezoneOffsetFromFormattedDateString as l, getGMTSuffixForTimezoneOffset as E } from "../../../../core/Localization/datetime/restamper/utils.js"; import { clock as M } from "../../../../primitives/time/clock/main.js"; import { isWatchlistUnsubscribeToken as _ } from "../../../../primitives/reactive/watchlist/main.js"; import G from "../../../../core/Localization/datetime/restamper/restamper.js"; import { EMPTY_OBJECT as O, EMPTY_ARRAY as S } from "../../../../utils/value/constants.js"; import { boolOrFalse as R } from "../../../../utils/value/bool.js"; import { noop as a } from "../../../../utils/common.js"; const { getTimezoneTime: U, getUsedTimezone: A } = (() => { const m = /\d{2}:\d{2}(?=:\d{2}(?:\.\d+)?\s+([AP]M))/i, n = /^GMT|0(?=\d:00)|:00/g, e = G(); return { getTimezoneTime: (t, i = Date.now()) => { e.tz = t; const { formatted: o } = e(i), [f = "", s = ""] = (o == null ? void 0 : o.match(m)) ?? S, u = l(o), z = `${f}${s && ` ${s}`}`, p = E(u).replace(n, ""); return [z, p]; }, getUsedTimezone: (t) => (e.tz = t, e.tz.current) }; })(), N = ({ timezone: m, withClock: n = !1 } = O) => { const e = c(() => R(n), [n]), r = c(() => A(m), [m]), T = d(a), [t, i] = g(Date.now()), [o, f] = c(() => U(r, t), [t, r]); return c(() => { T.current(), T.current = e ? M.subscribe((s) => { _(s) || i(s.now); }) : a; }, [i, e]), { clockTime: o, GMTOffset: f, timestamp: t, timezone: r }; }; export { N as default, U as getTimezoneTime, A as getUsedTimezone };