I Built a Tiny JavaScript Time Zone Engine - No Dependencies, No Bundled Time Zone Database
<h1>I Built a Tiny JavaScript Time Zone Engine — No Dependencies, No Bundled Time Zone Database</h1> <p> Time zones are the bug that keeps on giving. </p> <p> Most JavaScript applications either ship a separate time-zone database to the browser or quietly get daylight saving time (DST) wrong twice a year. </p> <p> While building <a href="https://timethen.com/">TimeThen</a>, a website of world…
This JavaScript time zone engine, named @timethen/time-engine, was created without any dependencies or a bundled time zone database. It is open source on npm and can be installed using 'npm install @timethen/time-engine'. The engine is designed to be lightweight at just 9 kB when packed, and it supports ESM (ECMAScript Modules) and TypeScript declarations.
The engine achieves its functionality by utilizing the time zone information provided by the JavaScript runtime through the Intl API. This allows it to perform various timezone operations with high accuracy, such as converting local times to timestamps, calculating working hour overlaps in different time zones, and determining the next time zone transition. It also handles daylight saving time (DST) and provides precise minute-level conversions.
The core idea behind @timethen/time-engine is to leverage the existing time zone data available in the JavaScript environment, rather than shipping a separate time zone database with the application. This approach has the advantage of automatically benefiting from updates to the runtime-provided time zone database, such as those introduced by the IANA Time Zone Database in 2026 for Canadian locations like British Columbia, Alberta, Northwest Territories, and Manitoba.
One notable feature of the engine is its ability to handle ambiguous local times caused by daylight saving time changes. It offers four disambiguation modes for converting local times to timestamps, including 'compatible' (default), 'earlier', 'later', and 'reject'. This ensures accurate calculations even in edge cases where local times do not exist or occur twice due to DST transitions.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.