native-dates

Guides / Start

Overview

Readable, immutable dates and times built on the browser's Temporal and Intl APIs.

Modern JavaScript engines include Temporal for calendar and time-zone math alongside Intl for localized formatting. Native Dates wraps those built-in APIs in plain English with zero runtime dependencies.

import { date, now, today } from 'native-dates';

const due = today().plus(2, 'weeks');
const standup = date('2026-11-16')
  .at('9:30am', 'America/Los_Angeles')
  .in('Europe/Berlin');

Because the runtime already carries the IANA time-zone database and locale rules, every region and language works without shipping extra zone or locale tables.

Separate types for separate jobs

JavaScript’s built-in Date uses one object whether you mean a holiday, an opening hour, or a database timestamp. Native Dates gives each concept its own type so values only carry the fields that make sense for them:

  • CalendarDate for a calendar day like May 10, 2026, unaffected by time zones
  • Time for a time of day like 9:30 AM, wrapping cleanly at midnight
  • DateTime for a specific moment paired with a time zone
  • Duration for a length of time like 90 minutes or 2 weeks
  • YearMonth and MonthDay for billing periods, card expiries, and recurring birthdays
  • Ranges for spans between two dates, times, or moments

Measuring gaps, building ranges, and formatting with localized presets or token patterns all work out of the box:

import { dateRange, datetime, monthDay, now, timeRange, yearMonth } from 'native-dates';

const deadline = datetime('2027-01-01T00:00:00Z');
now().until(deadline).format('long');

const sprint = dateRange('2026-11-02', '2026-11-15');
const shift = timeRange('9:00am', '5:00pm');
sprint.contains('2026-11-10'); // true
shift.duration.hours; // 8

const billing = yearMonth('2026-11');
const birthday = monthDay('10/17');

Read Types of time next to see how to pick between them and move from one to another.

Immutable values

Every instance is immutable. Calling methods like plus() or in() always returns a new value and leaves the original untouched.

Passing a date into a helper or UI component can never mutate caller state behind your back:

const original = date('2026-11-16').at('9:30am', 'America/Los_Angeles');
const moved = original.plus(1, 'hour');

original.text; // 'Nov 16, 2026, 9:30 AM PST'
moved.text; // 'Nov 16, 2026, 10:30 AM PST'

Every value also includes a .text getter with a human-readable summary in its active locale, and custom util.inspect output so console.log() in Node prints a concise single-line preview:

import { time } from 'native-dates';

date('2026-05-10').text; // 'May 10, 2026'
time('9:30am').text; // '9:30 AM'

Comparing values

Because methods return new instances, === checks object references rather than value equality. Call equals() to check whether two instances represent the same date, time, or moment.

Core and plugins

The core native-dates package covers creation, time zones, calendar math, partial dates, ranges, durations, relative phrases, localized presets, and token patterns.

Optional plugins for city and abbreviation lookups, loose parsing, and legacy Date methods live in @native-dates/plugins as individual subpath imports. See Customization to add plugins or configure app-wide defaults.

Head to Installation to add the package to your project and set up polyfilling if you support Safari.

Edit this pageUpdated Nov 16, 2026