Examples / Localization
French casing, ranges, and regional clocks
Format French dates without weekday commas, compare Paris and Québec 24-hour clock separators, and collapse multi-day spans.
Try this
- Change Time to 14:45 to compare
14:45infragainst14 h 45infr-CA. - Set Days to 20 so the collapsed span crosses into June and expands from
15–19 mai 2026to both month names. - Pick another day in Date to watch lowercase weekdays flow directly into the day number with no comma.
import { configure, date } from 'native-dates';
configure({ locale: 'fr' });
const day = document.querySelector('#day');
const clock = document.querySelector('#clock');
const span = document.querySelector('#span');
const output = document.querySelector('#output');
function render() {
if (!day.value || !clock.value || span.value === '') {
return;
}
const start = date(day.value);
const paris = start.at(clock.value, 'Europe/Paris');
const montreal = start.at(clock.value, 'America/Montreal').locale('fr-CA');
const range = start.to(start.plus(Number(span.value), 'days'));
output.innerHTML = `
<dt>Full date <code>.format('full')</code></dt>
<dd>${start.format('full')}</dd>
<dt>France clock <code>.format('long')</code></dt>
<dd>${paris.format('long')}</dd>
<dt>Québec clock <code>.locale('fr-CA')</code></dt>
<dd>${montreal.format('long')}</dd>
<dt>Collapsed range <code>.text</code></dt>
<dd>${range.text}</dd>`;
}
for (const control of [day, clock, span]) {
control.addEventListener('input', render);
}
render();
Starting…
How it works
Calling configure({ locale: 'fr' }) once applies French casing and punctuation across every value. Calling start.format('full') outputs “vendredi 15 mai 2026” in lowercase with no comma after the weekday.
Pairing the date with a clock time in Europe/Paris inserts the accented preposition “à” before the 24-hour time. With French configured, paris.format('long') separates hours and minutes with a colon as “09:30”.
Attach .locale('fr-CA') to a Montréal moment when comparing regional conventions. Québec typography writes “09 h 30” with a spaced “h” marker instead of a colon.
Reading range.text keeps shared month and year names once, rendering “15–19 mai 2026” and expanding both months when crossing a month boundary.