Skip to content
Source
Sign inSign up

scheduledTaskTimeZone.ts

23 lines804 Bytes

1import * as DateTime from "effect/DateTime";
2​
3/**
4 * Short label for the server zone a fixed-time schedule runs in. With a run time it names
5 * that instant's offset (PST/PDT); without one it uses the generic name (PT).
6 */
7export function scheduleTimeZoneLabel(
8 timeZone: string | undefined,
9 runAt?: string | null,
10): string | undefined {
11 if (timeZone === undefined) return undefined;
12 if (timeZone === "Etc/UTC" || timeZone === "UTC" || timeZone === "GMT") return "UTC";
13 try {
14 return new Intl.DateTimeFormat("en-US", {
15 timeZone,
16 timeZoneName: runAt ? "short" : "shortGeneric",
17 })
18 .formatToParts(runAt ? DateTime.toEpochMillis(DateTime.makeUnsafe(runAt)) : undefined)
19 .find((part) => part.type === "timeZoneName")?.value;
20 } catch {
21 return undefined;
22 }