Every factory parses strict ISO 8601 strings by default and throws on malformed input. Importing this plugin enables { loose: true } for untrusted user text, CSV columns, and legacy headers.
Strict parsing stays the default wherever you omit loose mode. Importing the plugin never alters existing calls across your codebase.
Reading in the active locale
Loose mode reads back the dates and clock times Intl prints for the active locale. Month names, AM/PM and part-of-day phrases, and numeric day-month order come from the runtime, and digits from any script fold automatically.
The active locale follows the same order as formatting: the locale option, then configure(), then the runtime default.
import '@native-dates/plugins/loose';import { configure, date, datetime, time } from 'native-dates';configure({ locale: 'es' });date('06/11/2026', { loose: true })?.toString(); // '2026-11-06'date('16 de noviembre de 2026', { loose: true })?.toString(); // '2026-11-16'time('9:10 de la noche', { loose: true })?.toString(); // '21:10:00'datetime('16 nov 2026, 14:30', { loose: true, zone: 'Europe/Madrid',})?.hour; // 14
import '@native-dates/plugins/loose';import { configure, date, datetime, time } from 'native-dates';configure({ locale: 'pt-BR' });date('06/11/2026', { loose: true })?.toString(); // '2026-11-06'date('16 de novembro de 2026', { loose: true })?.toString(); // '2026-11-16'time('9:10 da noite', { loose: true })?.toString(); // '21:10:00'datetime('16 de novembro de 2026 às 14:30', { loose: true, zone: 'America/Sao_Paulo',})?.hour; // 14
Year-first locales like Korean read two-digit years at the start, so '26. 5. 5.' reads as May 5, 2026 in Korean. Connecting words, ordinals, and leading weekday names are skipped across full dates and partial dates alike.
Returning null on bad data
With loose mode enabled, unreadable strings, empty fields, missing values, and impossible calendar dates like February 30 return null instead of throwing. Form handlers and import scripts can check the result directly without wrapping every field in a try block.
Incomplete dates missing a year or day return null in date and datetime factories instead of inventing a default. Use a partial-date factory when only a month and year or month and day are present.
Two-digit years beside a non-English month name, ambiguous month abbreviations, hours past 12 beside AM or PM, and bare clocks passed to datetime() are rejected. Unknown uppercase zone codes and bare hours like '14h' return null as well.
Bad data returns null, bad options still throw
Loose mode only handles unreadable input data. Passing an unknown time zone like 'Mars/Olympus' is a mistake in application code rather than user input, so it still throws immediately.
Time zones on loose strings
Strings carrying a UTC marker or numeric offset identify a specific moment and convert it into your target or configured zone. Strings without an offset keep the exact date and time written in the text and place them directly in your target zone.
A zone abbreviation after a clock time resolves using the same rules as the zone option. Load @native-dates/plugins/zones to read abbreviations beyond UTC, GMT, and standard IANA IDs, including locale-specific codes like CST under Chinese locales.
Day-first numeric dates
Numeric dates written with slashes, dots, or hyphens follow the active locale’s order automatically. Pass dayFirst per call or set it in configure() when an input uses a different order than the active locale.
Pass dayFirst: null to configure() to follow the active locale again. Partial date factories like monthDay() always read numeric pairs in the order their name states, regardless of locale.
Regional clock and month rules
Dotted clocks like '14.30' parse only in locales whose clock uses a dot, such as Finnish and Danish, and return null elsewhere. Dotted seconds parse after a date, while standalone three-part dotted strings stay dates.
Part-of-day phrases like English in the evening and Korean 밤 shift 12-hour clocks while leaving 24-hour times untouched. Date-to-time connectors are never read as AM or PM, so Welsh am, meaning “at”, keeps 14:30 intact while English 'AM 12:30' reads as midnight.
Inflected and affixed month forms written in full dates parse automatically, including Hebrew and Basque. Shortened month names must match a single month, so French juil parses as July while jui returns null.
Extends every factory with locale-aware fallback parsing and null returns on unreadable input. Calling class constructors like new DateTime() with { loose: true } enables fallback parsing while still throwing if the input cannot be read.
Parameters
loosebooleandefault false
Read informal text in the active locale, fall back to engine Date parsing for machine formats, and return null when unreadable.
dayFirstboolean
Override the active locale's numeric date order for strings like '07.09.2026'.
zoneZone
Time zone used to interpret local date-time strings or view instants.
localeLocale
BCP 47 locale tag carried on the value and used for month names, day-period words, clock style, and date order.
disambiguationDisambiguationdefault 'compatible'
How to resolve DST gaps and folds on local date-time strings. 'reject' returns null in loose mode.
Returns
DateTime | CalendarDate | Time | Duration | YearMonth | MonthDay | Range | null
Parsed instance, or null when input cannot be read.
Overrides the default numeric date order for loose calls that specify neither dayFirst nor locale per call. Unset by default so loose mode follows the active locale.
Parameters
dayFirstboolean | null
Pin loose numeric dates to day-first (true) or month-first (false), or pass null to follow the active locale.