Timezone

UTCTimeZone

Union type listing all IANA zone names that have a fixed UTC±00:00 offset (no DST).

reference/timezone/UTCTimeZone.ts
import { isUTC, type UTCTimeZone } from "datezone";

const timezone: UTCTimeZone = "UTC";
const result = isUTC(timezone);
console.log(result); // true

DSTTimeZone

Union type listing IANA zones that observe Daylight Saving Time and therefore change their offset during the year.

reference/timezone/DSTTimeZone.ts
import type { DSTTimeZone } from "datezone";

const _timezone: DSTTimeZone = "America/New_York";

// @ts-expect-error
const _nonDstTimeZone: DSTTimeZone = "Asia/Tokyo";

NoDSTTimeZone

Union type for every IANA zone that is not a DST timezone.

reference/timezone/NoDSTTimeZone.ts
import { isDST, isUTC, type NoDSTTimeZone } from "datezone";

const timezone: NoDSTTimeZone = "Asia/Tokyo";
const result1 = isDST(timezone);
console.log(result1); // false

const result2 = isUTC(timezone);
console.log(result2); // false

TimeZone

All IANA timezones; represents any valid timezone string accepted by Datezone.

reference/timezone/TimeZone.ts
import { format, type TimeZone } from "datezone";

const timezone: TimeZone = "America/New_York";
const formatted = format(Date.now(), timezone, {
	timeZone: "America/New_York",
});
console.log(formatted);

isUTC

Checks if a timezone is UTC.

reference/timezone/isUTC.ts
import { isUTC, type UTCTimeZone } from "datezone";

const timezone: UTCTimeZone = "Africa/Dakar";
const result = isUTC(timezone);
console.log(result); // true

isDST

Checks if a timezone is a DST timezone. (DST = Daylight Saving Time) If the timezone do not have DST we can do simple arithmetic to get the correct time.

reference/timezone/isDST.ts
import { type DSTTimeZone, isDST } from "datezone";

const timezone: DSTTimeZone = "Europe/Berlin";
const result = isDST(timezone);
console.log(result); // true

getLocalTimezone

Returns the IANA timezone string for the user's local environment.

reference/timezone/getLocalTimezone.ts
import { getLocalTimezone } from "datezone";

const tz = getLocalTimezone();
console.log("Local timezone:", tz);

On this page