hasDaylightSaving
Signature
Section titled “Signature”hasDaylightSaving(timeZone: string, options?: { at?: string; }): booleanCheck whether a timeZone observes daylight saving time at a reference instant.
- True when the zone is in daylight time at the reference instant, or a daylight period begins less than 365 days after it. So a zone in its winter is true, and a zone that has stopped changing its clocks is false.
- With
options.atthe answer does not depend on the day the code runs. - The rule is GMT’s own definition, not the tz database’s daylight flag, which no JavaScript API exposes: daylight time runs from a forward change of the zone’s clocks to the backward change of the same size that undoes it, less than 365 days later.
- Read as standard time, because the offsets do not show otherwise: the last summer before a zone kept its daylight offset for good; a daylight period held 365 days or longer; one that began, ended or was interrupted by a move of standard time, so the offset changes part-way through and the rest, or all, of it is not paired (
Asia/Tomsk2002); and one whose end is past the last instant Temporal can represent. - A forward change never undone is a change of standard time:
Europe/Istanbulis false from 2016 on, although its clocks went forward in March 2016. - Read from the runtime’s time zone data, so the answer can change when that data does.
- Returns false for an invalid timeZone, an invalid
at, an options argument that is not an object, and a fixed UTC offset, with or without seconds ("+05:30","-00:44:30").
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
timeZone | string | IANA name or UTC offset: a time zone identifier (+05:30, +0530, -08) or a stored offset (±HH:MM[:SS], what getTimeZoneOffset returns) |
Options
Section titled “Options”options
optional setting for the reference instant
| Option | Type | Default | Description |
|---|---|---|---|
at? | string | The current instant. | The reference instant the zone is judged at, as an ISO 8601 instant string ending in Z, an offset or a bracketed zone. It only names an instant, as isValidInstant reads it: a bracketed zone is not validated and does not replace timeZone. An invalid value returns false. |
Returns
Section titled “Returns”boolean indicating whether the timeZone observes DST, or false on invalid input
Examples
Section titled “Examples”import { hasDaylightSaving } from "@northguild/gmt/zoned/validate";
hasDaylightSaving("America/New_York", { at: "2024-01-15T12:00:00Z" }) // true