Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

How to Handle Daylight Saving Time Gaps and Overlaps in TypeScript

A local time can be missing or occur twice during a time-zone transition. Learn how Date resolves that ambiguity and how to choose an explicit Temporal policy in TypeScript.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When a local clock time may be missing or occur twice, give it a named time zone and choose an explicit resolution policy. JavaScript’s legacy Date silently uses “compatible” behavior: it shifts a nonexistent time forward by the gap and chooses the earlier occurrence of a repeated time. Temporal lets you choose that behavior deliberately—or reject the input.

Why a local time may not identify one instant

A date and clock time such as 1:30 a.m. is not enough to identify an instant. It also needs a time zone. Depending on that zone’s rules, a local date-time may correspond to no instant, one instant, or multiple instants. Daylight saving changes are a familiar cause, but governments can also change time-zone rules in other ways. The IANA time-zone database theory explains how those rules are represented.

As an Amazon Associate I earn from qualifying purchases.

A gap: the clock skips forward

When clocks move forward, a range of local times does not occur. If the clock jumps from 1:59 a.m. to 3:00 a.m., then 2:30 a.m. is a gap: there is no instant that corresponds to that wall-clock value in that zone on that date.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An overlap: the clock moves backward

When clocks move backward, a range of local times happens twice. The two occurrences of 1:30 a.m. have different offsets and correspond to different instants. The time-zone identifier and local clock value alone do not say which occurrence was intended.

What JavaScript Date does with ambiguous local input

When you construct a legacy Date from local date and time components, JavaScript applies compatible resolution. A nonexistent time is moved forward by the size of the gap; a repeated time resolves to the earlier instant. This behavior is documented by MDN’s Date reference.

This is convenient when that default matches the application’s intent, but it is implicit. TypeScript does not change the runtime semantics of Date: types can help validate your inputs, but they do not make a missing or repeated local time unambiguous.

Rank #2
TypeScript Programming Language - Software Engineer & Coder T-Shirt
  • TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
  • TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

Choose a disambiguation policy with Temporal

Temporal exposes the choice through the disambiguation option when converting a plain date-time to a zoned date-time. Its documented policies are compatible, earlier, later, and reject. See MDN’s Temporal.ZonedDateTime reference and Temporal overview.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Policy What it does in an overlap What it does in a gap Use when
compatible Selects the earlier occurrence. Moves forward by the gap, matching legacy Date. You want JavaScript’s familiar default behavior.
earlier Selects the earlier occurrence. Moves backward by the gap. The earlier-side interpretation is the intended rule.
later Selects the later occurrence. Moves forward by the gap. The later-side interpretation is the intended rule.
reject Throws rather than selecting an occurrence. Throws rather than adjusting the nonexistent time. The user or business logic must resolve ambiguity rather than accept a silent adjustment.

For example, a scheduling form can reject an ambiguous or nonexistent input and ask the user to choose a valid time. An import process with an established rule can select earlier or later. Choose based on the product’s promise, not merely on which option avoids an exception.

Store the right information for future schedules

Use the representation that matches what the value means. An event that has already happened is an exact instant, commonly serialized with a UTC designator such as Z. A birthday is usually a plain calendar date, not a moment in a time zone. A future appointment or recurring reminder generally needs a local date and time together with a named IANA time zone, such as America/New_York.

A numeric offset such as -04:00 describes the relationship to UTC at a particular time; it does not carry the region’s future transition rules. A named zone lets software interpret future local times according to the zone’s rules, which can change when governments change them. Temporal also documents controls for cases where a stored offset conflicts with updated zone rules in its ZonedDateTime documentation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Distinguish calendar days from elapsed hours

“Tomorrow at the same local time” is a calendar operation. “Twenty-four hours later” is an elapsed-duration operation. They can produce different results across a time-zone transition: a local calendar day can contain fewer or more than 24 elapsed hours.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

MDN’s Temporal.ZonedDateTime.prototype.add() documentation demonstrates adding one calendar day across New York’s fall-back transition: the local time remains 1:00 a.m. as the offset changes from UTC−04:00 to UTC−05:00, so that particular day spans 25 elapsed hours. Use zoned calendar arithmetic for “same local time tomorrow”; use instant or duration arithmetic for a fixed elapsed interval.

Decide which behavior your application needs

  • Is silent adjustment acceptable? If not, reject ambiguous and nonexistent inputs so the application can ask the user or report invalid data.
  • Which occurrence is intended? For an overlap, specify whether the earlier or later instant is correct instead of relying on an accidental default.
  • Is the promise about wall-clock time or elapsed time? Keep a local schedule aligned to a zone for calendar commitments; use instants and durations for fixed intervals.
  • Should future events follow regional rules? Keep the named zone when that is the intent. An offset alone cannot represent future changes to the region’s rules.

MDN summarizes the core ambiguity: “The reverse is not true: conversion from local time to UTC time, without an explicit offset, is ambiguous, because one local time can correspond to zero, one, or many UTC times.” The API documentation establishes Temporal’s disambiguation behavior, but does not provide a comprehensive current browser and runtime compatibility matrix; check the JavaScript environments your application supports before adopting it.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.