Guides / Start
Customization
Set app-wide defaults and extend Native Dates with custom formats or opt-in plugins.
By default, Native Dates follows the runtime’s local time zone and locale. Use configure() and opt-in plugins when your app needs fixed defaults, named formats, or extra parsing and zone features.
App-wide defaults
Call configure() at startup to set a default time zone, locale, or start of the week across your app. Omitted keys keep their current value, and passing null restores the runtime default:
import { configure, date, now } from 'native-dates';
configure({
zone: 'America/New_York',
locale: 'en-US',
weekStart: 'monday',
});
now().zone; // 'America/New_York'
date('2026-11-18').startOf('week').toString(); // '2026-11-16'Individual calls can still pass their own time zone, locale(), or week start to override the default.
Configure once at startup on servers
Global defaults are shared across the JavaScript process. On a multi-user server, attach each request’s zone and locale directly to the value instead of mutating configure() per request.
Named formats
Register named formats under formats and pass their names to format(). Each entry accepts a token pattern or an Intl options object:
import { configure, date, datetime } from 'native-dates';
configure({
formats: {
invoice: 'YYYY-MM-DD',
receipt: { weekday: 'long', month: 'long', day: 'numeric' },
},
});
date('2026-11-06').format('invoice'); // '2026-11-06'
const placed = datetime('2026-11-06T09:05', 'Europe/Berlin');
placed.format('receipt'); // 'Friday, November 6'Named formats apply to dates, times, partial dates, and ranges, while durations use only their built-in styles. Custom names take precedence over built-in presets, so registering 'short' overrides it across the app.
Adding plugins
Optional plugins for city lookups, lenient parsing, and legacy Date getters live in @native-dates/plugins:
npm i @native-dates/pluginsImport each subpath once at startup to enable it:
import '@native-dates/plugins/loose';
import '@native-dates/plugins/zones';
import { date, datetime } from 'native-dates';
datetime('2026-11-16T09:30', 'Berlin').zone; // 'Europe/Berlin'
date('Nov 16, 2026', { loose: true }); // CalendarDate(2026-11-16)Plugins can also register their own configure() options once loaded. The zones plugin adds zoneAliases for custom names, and the loose plugin adds dayFirst for numeric date order:
import '@native-dates/plugins/loose';
import '@native-dates/plugins/zones';
import { configure, date, now } from 'native-dates';
configure({
zoneAliases: { hq: 'Europe/Berlin' },
dayFirst: true,
});
now('hq').zone; // 'Europe/Berlin'
date('07.09.2026', { loose: true }).toString(); // '2026-09-07'Browse the Plugins overview to measure each subpath’s size, or read Writing a plugin to package your own.
Custom weekday names and ordinals
Month and weekday names come from the runtime’s Intl data. When a design calls for custom abbreviations or day ordinals, override them with weekdayNames and ordinals:
import { configure, date } from 'native-dates';
configure({
weekdayNames: {
en: { short: { tue: 'Tues', thu: 'Thurs' } },
},
ordinals: {
fr: (day) => (day === 1 ? '1er' : day),
},
});
date('2026-11-03').format('ddd', 'en-US'); // 'Tues'
date('2026-11-01').format('Do MMMM', 'fr'); // '1er novembre'Pass null for either key to return to the runtime and built-in defaults. Next, read Localization to handle per-user languages, week boundaries, and calendar systems.