formatDate and parseDate
formatDate(date, { locale }) writes a date in the locale's numbers, such as 10/13/2026 in en-US, 13.10.2026 in de and 2026. 10. 13. in ko. parseDate(text, { locale }) reads typed text back into a Temporal.PlainDate, or returns null when the text is not a date. Without locale, both use the runtime's own. Field.DateInput reads and writes its text with them, and they work in a Field.TextInput of your own too.
On this page
import { Code, DataList, Field, formatDate, Label, parseDate, Stack } from '@tounsoo/todae';
import { useId, useState } from 'react';
// What parseDate reads from the text, and how formatDate writes it back.
export default function DateRoundTrip({ locale }: { locale: string }) {
const id = useId();
const [text, setText] = useState('2026-10-13');
const value = parseDate(text, { locale });
return (
<Stack.Root gap="condensed">
<Field.Group>
<Label.Root htmlFor={id}>Due date</Label.Root>
<Field.Root id={id}>
<Field.TextInput value={text} onChange={(event) => setText(event.target.value)} />
</Field.Root>
</Field.Group>
<DataList.Root aria-label="Round trip">
<DataList.Item>
<DataList.Term>parseDate</DataList.Term>
<DataList.Details>
<Code.Root>{value === null ? 'null' : value.toString()}</Code.Root>
</DataList.Details>
</DataList.Item>
<DataList.Item>
<DataList.Term>formatDate</DataList.Term>
<DataList.Details>
<Code.Root>{value === null ? 'null' : formatDate(value, { locale })}</Code.Root>
</DataList.Details>
</DataList.Item>
</DataList.Root>
</Stack.Root>
);
}
- parseDate
2026-10-13- formatDate
10/13/2026
What parseDate reads
It reads a date in numbers in the order formatDate writes them or in the order of the locale's short date style, as 13.10.26 in gsw, whose formatDate writes 2026-10-13. When both orders read a date, a year of four or more digits is read in formatDate's order, and a year of one or two digits in the short style's order when that style writes the year in two digits. It also reads a date as Intl.DateTimeFormat writes it in the locale's medium, long or full date style, such as Oct 13, 2026 or Tuesday, October 13, 2026 in en-US.
Letter case doesn't matter, digits may be in any script, and the parts may be separated by any punctuation, symbols or spaces. The month may be any of its long or short names, such as Oct or October. A weekday may be long, short or left out, but must be the date's. The style's other words, such as de in 13 de octubre de 2026, may be replaced by a space. Three numbers that start with a year of four or more digits, such as 2026-10-13, are read as year, month and day, unless the locale writes the year first in another order. A year is a Gregorian year, whatever the locale's own calendar. A year of one or two digits is read as the nearest such year to the current one, so a date about 50 years away needs all four digits, and a year of three digits is not read.
Temporal
Todae ships no Temporal polyfill. Both use Temporal.PlainDate, so where the browser has no Temporal, the app loads a polyfill (see Native platform).
Accessible composition
Todae handles: Text in the locale you pass, or the runtime's own when you pass none.
You supply: A locale that matches the page's, and the same one for writing and reading. A message near the input when parseDate returns null.
Watch for: On a server with no locale, the text uses the server's locale. Text that reads as a date but not the one meant, such as a two-digit year read as the nearest such year: show the date in words nearby when that matters.
When to use
formatDate
When: Writing a date as text for a locale, such as into a text input of your own.
When not: A date with a weekday or a month name → Intl.DateTimeFormat.
parseDate
When: Reading a date someone typed.
When not: Text in a fixed format such as 2026-10-13 → Temporal.PlainDate.from.
Props
| Name | Type | Description |
|---|---|---|
date Required | Temporal.PlainDate | The date to write. |
options.locale | string | The locale, such as ko. The runtime's own when not set. |
| Name | Type | Description |
|---|---|---|
text Required | string | The typed text. |
options.locale | string | The locale, such as ko. The runtime's own when not set. |