Skip to content

DateRange

Displays a formatted date range with start and end dates. Shows "Present Time" when no end date is provided. Supports localization via the locale prop.

Also known as: period, time range, duration, date span

View in Storybook

When to use

  • Displaying employment or project duration on profiles and resumes.
  • Showing event date ranges.
  • Indicating active periods with "Present Time" for ongoing items.

Import

tsx
import { DateRange } from '@vacano/ui'

Usage (ongoing)

When to is omitted, displays "Present Time" as the end date.

tsx
<DateRange from={new Date(2021, 9)} />
// Renders: # October 2021 — Present Time

With end date

tsx
<DateRange from={new Date(2019, 6)} to={new Date(2021, 8)} />
// Renders: # July 2019 — September 2021

Localization

Use the locale prop to display month names in the desired language. Accepts any valid BCP 47 language tag. Formatting is handled by Intl.DateTimeFormat.

tsx
<DateRange from={new Date(2023, 2)} to={new Date(2025, 11)} locale="ru" />
// Renders: # март 2023 г. — декабрь 2025 г.

<DateRange from={new Date(2023, 2)} to={new Date(2025, 11)} locale="de" />
// Renders: # März 2023 — Dezember 2025

Custom present label

When using locale, remember to localize presentLabel as well:

tsx
<DateRange from={new Date(2023, 2)} locale="ru" presentLabel="По настоящее время" />
// Renders: # март 2023 г. — По настоящее время

Props

PropTypeDefaultDescription
fromDaterequiredStart date
toDate-End date. When omitted, presentLabel is shown instead.
localestring'en'BCP 47 language tag for month name localization (e.g. 'ru', 'de', 'fr', 'ja'). Uses Intl.DateTimeFormat internally.
presentLabelstring'Present Time'Label displayed when to is not set. Should be localized manually when using a non-English locale.
refRef<HTMLSpanElement>-Forwarded ref
classNamestring-CSS class name for the root element
classnamesDateRangeClassNames-Custom class names for sub-elements
data-test-idstring-Test identifier attribute

ClassNames

KeyDescription
hashThe # symbol
fromThe start date text
separatorThe em dash separator
toThe end date or present label text
  • Overline - Category label, often paired with DateRange
  • Heading - Heading component for titles
  • DatePicker - Interactive date selection

Released under the MIT License.