Offset
getUTCtoTimezoneOffsetMinutes
Returns the offset in minutes between UTC and the given timezone at the given date. Positive if the zone is ahead of UTC, negative if behind. Uses a per-hour cache for performance. If no timezone is specified, defaults to local system timezone.
reference/offset/getUTCtoTimezoneOffsetMinutes.ts
import { getUTCtoTimezoneOffsetMinutes } from "datezone";
const timestamp = 1720612800000; // 2024-07-10T12:00:00.000Z
const offset = getUTCtoTimezoneOffsetMinutes(timestamp, "America/New_York");
console.log(offset); // -240 (America/New_York is UTC-5)
getTimezoneOffsetMinutes
Returns the offset in minutes from fromZone to toZone at the given date. Fast path for UTC zones to avoid extra formatToParts calls. If timezone parameters are not specified, defaults to local system timezone.
reference/offset/getTimezoneOffsetMinutes.ts
import { getTimezoneOffsetMinutes } from "datezone";
const timestamp = 1720612800000; // 2024-07-10T12:00:00.000Z
const offset = getTimezoneOffsetMinutes(
timestamp,
"America/New_York",
"Asia/Tokyo",
);
console.log(offset); // 780
getFixedOffsetCacheInfo
Returns information about the fixed offset cache for debugging purposes.
reference/offset/getFixedOffsetCacheInfo.ts
import { getFixedOffsetCacheInfo } from "datezone";
const info = getFixedOffsetCacheInfo();
console.log(info); // { size: 0, cachedTimezones: [] }
clearFixedOffsetCache
Clears the fixed offset cache. Useful for testing or memory management.
reference/offset/clearFixedOffsetCache.ts
import { clearFixedOffsetCache } from "datezone";
clearFixedOffsetCache();
getUTCtoLocalOffsetMinutes
Returns the offset in minutes between UTC and the local timezone for a given date.
reference/offset/getUTCtoLocalOffsetMinutes.ts
import { getUTCtoLocalOffsetMinutes } from "datezone";
const timestamp = 1720612800000; // 2024-07-10T12:00:00.000Z
const offset = getUTCtoLocalOffsetMinutes(timestamp);
console.log(offset); // 780 (Depends on the local timezone)