@quadible/web-sdk
Version:
The web sdk for Quadible's behavioral authentication service.
28 lines • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = getTimezone;
const data_1 = require("../utils/data");
function getTimezone() {
const DateTimeFormat = window.Intl?.DateTimeFormat;
if (DateTimeFormat) {
const timezone = new DateTimeFormat().resolvedOptions().timeZone;
if (timezone) {
return timezone;
}
}
// For browsers that don't support timezone names
// The minus is intentional because the JS offset is opposite to the real offset
const offset = -getTimezoneOffset();
return `UTC${offset >= 0 ? '+' : ''}${offset}`;
}
function getTimezoneOffset() {
const currentYear = new Date().getFullYear();
// The timezone offset may change over time due to daylight saving time (DST) shifts.
// The non-DST timezone offset is used as the result timezone offset.
// Since the DST season differs in the northern and the southern hemispheres,
// both January and July timezones offsets are considered.
return Math.max(
// `getTimezoneOffset` returns a number as a string in some unidentified cases
(0, data_1.toFloat)(new Date(currentYear, 0, 1).getTimezoneOffset()), (0, data_1.toFloat)(new Date(currentYear, 6, 1).getTimezoneOffset()));
}
//# sourceMappingURL=timezone.js.map