React playground

Nova v3.37.0

Preview

React

nv-calendar guide

Single and range selection, date formats and supported locales.

← nv-calendar

Features

  • Single & Range Selection: Allows choosing a single date or a range of dates.
  • Customizable Date Formats: Supports multiple formats, including ISO 8601, Unix Timestamps, and localized formats.
  • Disabled Dates: Restrict specific dates from being selected (currently works only for single selection mode).
  • Shortcuts: You can add your own shortcuts (e.g., Today, Last Week, Next Month).
  • Localization: Configurable language settings.
  • Multiple Calendars: Display multiple months at once.

Expected Behavior

Date Handling

  • The format in which a date is provided will be the format in which it is emitted.
  • No forced conversions between UTC and Local time.
  • The Min/Max are currently supported by the single mode and range mode.
  • Disabled dates are currently supported only in single selection mode (not yet implemented for range selection).
CaseInput singleValueDisplayed in CalendarEmitted singleDateChange
UTC Date2025-03-15T12:30:00.000ZShows March 15 in UTC2025-03-15T12:30:00.000Z
Local Date2025-03-15T12:30:00.000Shows March 15 in Local2025-03-15T12:30:00.000
Selecting a date in UTCDate picked in UTC modeDisplays correctlyEmits with Z suffix
Selecting a date in LocalDate picked in Local modeDisplays correctlyEmits without Z suffix

Supported Date Formats

The following date formats are supported:

NameFormatExample (Single)Example (Range)
ISO 8601YYYY-MM-DD[T]HH:mm:ss[Z]2025-03-15T00:00:00Z{ start: '2025-03-15T00:00:00Z', end: '2025-03-20T00:00:00Z' }
YYYY-MM-DDYYYY-MM-DD2025-03-15{ start: '2025-03-15', end: '2025-03-20' }
DD/MM/YYYYDD/MM/YYYY15/03/2025{ start: '15/03/2025', end: '20/03/2025' }
MM/DD/YYYYMM/DD/YYYY03/15/2025{ start: '03/15/2025', end: '03/20/2025' }
Compact YYYYMMDDYYYYMMDD20250315{ start: '20250315', end: '20250320' }
German DD.MM.YYYYDD.MM.YYYY15.03.2025{ start: '15.03.2025', end: '20.03.2025' }
Unix SecondsX1710441600{ start: '1710441600', end: '1710528000' }
Unix Millisecondsx1710441600000{ start: '1710441600000', end: '1710528000000' }
Short TextMMM DD YYYYMar 15 2025{ start: 'Mar 15 2025', end: 'Mar 20 2025' }
Long TextMMMM DD, YYYYMarch 15, 2025{ start: 'March 15, 2025', end: 'March 20, 2025' }
C# TicksTicks638430220000000000{ start: '638430220000000000', end: '638437132000000000' }

** All dates ('single value', 'range value', 'disabled dates', min, max) must be in the same date format as you will specify in the dateFormat property. **

Notes

  • The disabled dates feature currently works only for single selection mode.
  • The component does not enforce UTC or local conversions, leaving the choice to the user.
  • Shortcuts automatically apply the correct date format based on the configured dateFormat.

Supported Locales

The component provides localized translations for week abbreviations, allowing seamless adaptation to different regions.

LocaleWeek Abbreviation
fr-BESem
nl-BEW
en-BEW
de-DEKW (Kalenderwoche)
en-USW
fr-FRSem
en-GBW
es-ESSem
it-ITSet (Settimana)
pt-PTSem
nl-NLW
pl-PLTyd (Tydzień)
ru-RUНед (Неделя)
ja-JP週 (Shū)
zh-CN周 (Zhōu)
ko-KR주 (Ju)

How Localization Works

The locale setting of the <nv-calendar> component influences how dates and weeks are displayed. When a locale is specified using the locale property, the calendar automatically adapts the week abbreviation.

Example:

tsx<nv-calendar locale="fr-BE"></nv-calendar>

The week abbreviation will be displayed as "Sem" instead of "W".



Date Handling in nv-calendar

Objective

How Date Parsing Works

Step 1: Reading the singleValue or rangeValue Property

On initialization, the component processes the singleValue or rangeValue property to determine the date format:

  1. If the date is in UTC (ends with "Z")
    • It is stored and displayed in UTC without conversion to Local time.
  2. If the date is in Local format (no "Z")
    • It is stored and displayed in Local time.

Step 2: Selecting a Date or a Range in the Calendar

When the user selects a date or a range from the calendar:

  1. The selected date or range is retrieved as a Date object.
  2. The format (UTC or Local) is determined based on the input format.
  3. The date or range is formatted accordingly.
  4. If the input format was UTC, the "Z" is added to the emitted value.
  5. The singleDateChange or rangeDateChange event is emitted with the correctly formatted date or range.

exemple singlevalue returned:

ts{
    singleDateChange: CustomEvent {bubbles: true, cancelBubble: false, cancelable: true, composed: true, currentTarget: HostElement…}
    bubbles: true
    cancelBubble: false
    cancelable: true
    composed: true
    currentTarget: HostElement
    defaultPrevented: false
    detail: "2025-03-18" <----- // returned value
    eventPhase: 2
    isTrusted: false
    returnValue: true
    srcElement: HostElement
    target: HostElement
    timeStamp: 5840979.5
    type: "singleDateChange"
    }

exemple rangevalue returned:

ts{
    rangeDateChange: CustomEvent {bubbles: true, cancelBubble: false, cancelable: true, composed: true, currentTarget: HostElement…}
    bubbles: true
    cancelBubble: false
    cancelable: true
    composed: true
    currentTarget: HostElement
    defaultPrevented: false
    detail: Object
    end: Sat Mar 08 2025 01:00:00 GMT+0100 (Central European Standard Time) <----- // returned value
    start: Sun Mar 02 2025 01:00:00 GMT+0100 (Central European Standard Time) <----- // returned value
    eventPhase: 2
    isTrusted: false
    returnValue: true
    srcElement: HostElement
    target: HostElement
    timeStamp: 5904337.1999999285
    type: "rangeDateChange"
    }

Expected Behavior

CaseInput singleValueDisplay in CalendarEmitted singleDateChange
UTC Date"2024-03-15T12:30:00.000Z"Displays March 15 in UTC"2024-03-15T12:30:00.000Z"
Local Date"2024-03-15T12:30:00.000"Displays March 15 in Local"2024-03-15T12:30:00.000"
Selecting a date in UTCDate selected in UTC modeDisplays correctlyEmits with Z suffix
Selecting a date in LocalDate selected in Local modeDisplays correctlyEmits without Z suffix

Summary

  • The component does not convert between UTC and Local; it respects the original format.
  • If the input is in UTC, the emitted value will retain UTC format.
  • If the input is in Local time, the emitted value will retain Local time.
  • This ensures full control over date handling is in the hands of the user and not imposed by the component.