@adyen/adyen-platform-experience-web
Version:

43 lines (42 loc) • 1.31 kB
JavaScript
import { SYSTEM_TIMEZONE as n, SYSTEM_TIMEZONE_FORMATTER as f, BASE_LOCALE as a, BASE_FORMAT_OPTIONS as c } from "./constants.js";
import { getTimezoneOffsetForTimestamp as E } from "./utils.js";
import { struct as T } from "../../../../utils/struct/main.js";
import { isUndefined as O, isNullish as u } from "../../../../utils/value/is.js";
const Z = (() => {
let o, i;
O(n) || (o = function() {
return this.TIMEZONE;
}, i = function(t) {
if (u(t))
this.TIMEZONE = n, this.formatter = f;
else
try {
const e = new Intl.DateTimeFormat(a, { ...c, timeZone: t }), r = e.resolvedOptions().timeZone;
if (this.TIMEZONE === r) return;
this.TIMEZONE = r, this.formatter = e;
} catch {
}
});
function s(...t) {
if (t.length === 0)
return s.call(this, Date.now());
const e = t[0], r = new Date(e).getTime(), m = this.formatter ?? f;
return Object.freeze({
formatted: m?.format(new Date(r)),
offset: E(r, m),
timestamp: r
});
}
return () => {
const t = { TIMEZONE: n }, e = i?.bind(t), r = T({
current: { get: o?.bind(t), set: e },
system: { value: n }
});
return Object.defineProperties(s.bind(t), {
tz: { get: () => r, set: e }
});
};
})();
export {
Z as default
};