Introduction
Datezone is a lightweight, high-performance date and timezone utility library for JavaScript and TypeScript. It provides a simple, modern API for parsing, formatting, comparing, and working with dates and times. Every function includes full support for IANA timezones and DST.
import { startOfDay, toISOString } from "datezone";
const now = startOfDay(Date.now(), "Asia/Singapore");
console.log(toISOString(now, "America/New_York"));
🎯 Why Datezone
Because Date & Time in JavaScript is really hard!
JavaScript's native Date
object has no timezone support. Existing libraries need extra plugins like @date-fns/tz
or date-fns-tz
that add complexity with wrapper objects like TZDate
.
Datezone is built from the ground up with timezones and DST support built into every function. No plugins or special wrapper objects needed.
🏗️ Modern Architecture
- Built on the modern Intl API and math calculations instead of relying on the Date object
- Performance first - uses timestamps to be memory efficient
- Made to run 1000 times a second without performance loss
- Easier to send over HTTP with timestamp-based operations
🚀 Blazing Fast Performance
- 18,000%+ faster in timezone operations
- 45,000%+ faster for simple date math
- No performance loss as your app scales
See Comparison and Benchmarks
📦 Developer Experience
- ESM only tree-shaking - only import what you use
- 100% TypeScript with strict types that catch errors at compile time
- Zero dependencies - no extra packages to worry about
- 33.76KB total size, competitive with major alternatives
🌍 Native Timezone Excellence
- Timezones built into every function - no plugins required
- Native IANA timezone support with automatic DST handling
import { addDays, calendarToTimestamp, format, type TimeZone } from "datezone";
// 💡 Instead of using browser timeZone,
// store users preferred timeZone in session storage or database.
const timeZone: TimeZone = "America/New_York";
const locale = "en-US";
// Convert a calendar date to timestamp
const date = calendarToTimestamp(2024, 6, 1, 0, 0, 0, 0, timeZone);
// Add 5 calendar days in New York Timezone
const future = addDays(date, 5, timeZone);
// Format the date in New York Timezone with the user's locale
const result = format(future, "yyyy-MM-dd HH:mm:ss", {
locale,
timeZone,
});
console.log(result); // 2024-06-06 00:00:00
// Or if you want to format in Different Timezone
const tokioResult = format(future, "yyyy-MM-dd HH:mm:ss", {
locale,
timeZone: "Asia/Tokyo",
});
console.log("Same date & time in Tokyo:", tokioResult); // 2024-06-06 13:00:00
Why do we need to specify a timezone when adding days?
Isn't 1 day always 24 hours (86,400 seconds)?
Not always! Due to Daylight Saving Time (DST) transitions, some days are 23 or 25 hours long.
Example: In the America/New_York
timezone on March 11, 2023 at 1:00 PM EST:
- Simply adding 24 hours would result in March 12, 2023 at 2:00 PM EDT
- But the correct "1 day later" should be March 12, 2023 at 1:00 PM EDT
- This is because March 12, 2023 was only 23 hours long due to the spring DST transition
Summary: The length of a day changes depending on the timezone and DST transitions. That's why timezone-aware day calculations are essential for accurate date math.
Get Started
Check out the Installation or take a deep dive into how DST Transition works.