native-dates

Examples / Localization

German ordinal periods, spans, and calendar weeks

Format German dates with ordinal periods and capitalized nouns, collapse day spans, and compute ISO Kalenderwochen across year boundaries.

Try this

  1. Click 2027-01-01 to see Friday, January 1 stay in KW 53 of the previous ISO week-year.
  2. Pick 2027-01-04 in Date to watch the first Monday of January start KW 1.
  3. Set Days to 35 on 2026-05-01 so range.format('long') keeps ordinal periods across May and June.
import { configure, date } from 'native-dates';

configure({ locale: 'de' });

const day = document.querySelector('#day');
const span = document.querySelector('#span');
const output = document.querySelector('#output');

function render() {
  if (!day.value || span.value === '') {
    return;
  }
  const start = date(day.value);
  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>Collapsed range <code>.format('long')</code></dt>
    <dd>${range.format('long')}</dd>
    <dt>Numeric date <code>.text</code></dt>
    <dd>${start.text}</dd>
    <dt>ISO calendar week <code>KW</code></dt>
    <dd>${'KW ' + start.format('W')}</dd>`;
}

for (const button of document.querySelectorAll('[data-date]')) {
  button.addEventListener('click', () => {
    day.value = button.dataset.date;
    render();
  });
}

day.addEventListener('input', render);
span.addEventListener('input', render);
render();

Starting…

How it works

Calling configure({ locale: 'de' }) once applies German capitalization and ordinal periods across every value. Calling start.format('full') produces “Freitag, 1. Mai 2026” with the comma and dot in place.

Date spans retain the ordinal period on both day numbers through range.format('long'). A four-day May span prints “1.–5. Mai 2026” without dropping the dot after the starting day.

Everyday numeric dates in Germany, Austria, and Switzerland separate day, month, and year with dots. Reading start.text outputs zero-padded “01.05.2026” directly from Intl.

Work schedules across German-speaking countries track weeks by ISO Kalenderwoche, abbreviated “KW”. Calling format('W') assigns January 1, 2027 to “KW 53” because ISO week 1 starts on January 4.