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).
| Case | Input singleValue | Displayed in Calendar | Emitted singleDateChange |
|---|---|---|---|
| UTC Date | 2025-03-15T12:30:00.000Z | Shows March 15 in UTC | 2025-03-15T12:30:00.000Z |
| Local Date | 2025-03-15T12:30:00.000 | Shows March 15 in Local | 2025-03-15T12:30:00.000 |
| Selecting a date in UTC | Date picked in UTC mode | Displays correctly | Emits with Z suffix |
| Selecting a date in Local | Date picked in Local mode | Displays correctly | Emits without Z suffix |
Supported Date Formats
The following date formats are supported:
| Name | Format | Example (Single) | Example (Range) |
|---|---|---|---|
| ISO 8601 | YYYY-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-DD | YYYY-MM-DD | 2025-03-15 | { start: '2025-03-15', end: '2025-03-20' } |
| DD/MM/YYYY | DD/MM/YYYY | 15/03/2025 | { start: '15/03/2025', end: '20/03/2025' } |
| MM/DD/YYYY | MM/DD/YYYY | 03/15/2025 | { start: '03/15/2025', end: '03/20/2025' } |
| Compact YYYYMMDD | YYYYMMDD | 20250315 | { start: '20250315', end: '20250320' } |
| German DD.MM.YYYY | DD.MM.YYYY | 15.03.2025 | { start: '15.03.2025', end: '20.03.2025' } |
| Unix Seconds | X | 1710441600 | { start: '1710441600', end: '1710528000' } |
| Unix Milliseconds | x | 1710441600000 | { start: '1710441600000', end: '1710528000000' } |
| Short Text | MMM DD YYYY | Mar 15 2025 | { start: 'Mar 15 2025', end: 'Mar 20 2025' } |
| Long Text | MMMM DD, YYYY | March 15, 2025 | { start: 'March 15, 2025', end: 'March 20, 2025' } |
| C# Ticks | Ticks | 638430220000000000 | { 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
dateFormatproperty. **
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.
| Locale | Week Abbreviation |
|---|---|
fr-BE | Sem |
nl-BE | W |
en-BE | W |
de-DE | KW (Kalenderwoche) |
en-US | W |
fr-FR | Sem |
en-GB | W |
es-ES | Sem |
it-IT | Set (Settimana) |
pt-PT | Sem |
nl-NL | W |
pl-PL | Tyd (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:
<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:
- If the date is in UTC (ends with "Z")
- It is stored and displayed in UTC without conversion to Local time.
- 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:
- The selected date or range is retrieved as a
Dateobject. - The format (UTC or Local) is determined based on the input format.
- The date or range is formatted accordingly.
- If the input format was UTC, the "Z" is added to the emitted value.
- The
singleDateChangeorrangeDateChangeevent is emitted with the correctly formatted date or range.
exemple singlevalue returned:
{
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:
{
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
| Case | Input singleValue | Display in Calendar | Emitted 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 UTC | Date selected in UTC mode | Displays correctly | Emits with Z suffix |
| Selecting a date in Local | Date selected in Local mode | Displays correctly | Emits 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.