native-dates

Examples / Localization

Russian month cases and plural counts

Format Russian stand-alone nominative months, genitive full dates, collapsed date ranges, and three-way plural durations.

Try this

  1. Compare the first two rows to see YearMonth print nominative май while the full date inflects to genitive 1 мая.
  2. Click 1, 2, 5, 11, and 21 to watch days() cycle through день, дня, and дней, including the teen exception at 11.
  3. Pick a March or August date to watch other Russian month endings inflect between heading and date forms.
import { configure, date, days } from 'native-dates';

configure({ locale: 'ru' });

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

function render() {
  const total = Number(count.value);
  if (!dayInput.value || !(total >= 1)) { return; }
  const day = date(dayInput.value);
  const span = day.to(day.plus(4, 'days'));

  const rows = [
    ['Month heading', '.yearMonth.text', day.yearMonth.text],
    ['Full date', '.text', day.text],
    ['Date range', '.text', span.text],
    ['Plural count', '.text', days(total).text],
  ];

  output.innerHTML = rows.map(([label, locale, value]) => `
    <li>
      <span class="label">${label} <code>${locale}</code></span>
      <b>${value}</b>
    </li>`).join('');
}

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

dayInput.addEventListener('input', render);
count.addEventListener('input', render);
render();

Starting…

How it works

Calling configure({ locale: 'ru' }) once applies Russian month cases and plural declensions everywhere. Reading day.yearMonth.text selects the nominative stand-alone month for headings, while full dates switch to the genitive case automatically.

Date ranges collapse the shared month and year across an en-dash. Reading span.text keeps the shared month in its genitive form, producing 1–5 мая 2026 г. without manual templates.

Duration counts apply Russian’s three-way plural rules directly on days(total).text. Counts ending in one like twenty-one return singular день, while teen numbers from eleven through fourteen take the plural genitive instead.