Skip to content

Guide of the date and time picker ​

Install ​

sh
npm install @nervure/datetime

Or one file from a CDN. It registers <nv-datetime> and gives window.nervureDateTime:

html
<script src="https://cdn.jsdelivr.net/npm/@nervure/datetime@0.1.0"></script>

Four ways to use it ​

Plain JavaScript ​

On a text field, the panel opens under it. On any other element, the calendar is drawn inside it.

js
import { createDatePicker } from '@nervure/datetime';

const picker = createDatePicker('#start', {
  value: '2026-12-04',
  locale: 'fr',
  onChange: (selection) => console.log(selection.value, selection.start, selection.end),
});

Web component ​

html
<script type="module">import '@nervure/datetime/element';</script>

<nv-datetime mode="range" presets locale="fr" zone="Europe/Paris" name="period"></nv-datetime>

Attributes: mode, value, zone, zones, locale, min, max, months, time, seconds, minute-step, hour12, first-day, week-numbers, presets, granularity, granularities, compare, orientation, inline, placeholder, accent, theme, name, disabled.

A range is written 2026-01-01/2026-03-31. Several days are written 2026-01-01,2026-01-05. The change event carries the selection in event.detail. Options that an attribute cannot carry go through the options property: el.options = { disable: (date, weekday) => weekday >= 5 }.

This works as it is in Svelte, Angular, Astro, Twig and Blade.

React ​

jsx
import { useState } from 'react';
import { DateTimePicker } from '@nervure/datetime/react';

function Period() {
  const [value, setValue] = useState({ start: '2026-12-01', end: '2026-12-31' });
  return <DateTimePicker mode="range" presets value={value} onChange={(s) => setValue(s.value)} />;
}

Vue ​

vue
<script setup>
import { ref } from 'vue';
import { NvDateTime } from '@nervure/datetime/vue';
const quarter = ref('2026-Q4');
</script>

<template>
  <NvDateTime v-model="quarter" mode="quarter" :options="{ locale: 'fr' }" />
</template>

Modes and values ​

Every value is ISO 8601 text. You can store it, send it and compare it as it is.

ModeThe reader picksValue
dateone day2026-12-04
date with time: trueone day and an hour2026-12-04T14:30+01:00
rangea first and a last day{ start: '2026-12-01', end: '2026-12-31' }
multipleseveral days['2026-12-04', '2026-12-11']
weekan ISO week2026-W49
montha month2026-12
quartera quarter2026-Q4
yeara year2026
timea time of day14:30
perioda period, on a tab: day, week, month, quarter, year or free range{ start: '2026-10-01', end: '2026-12-31' }

onChange and getSelection() give more than the value:

js
{
  mode: 'quarter',
  value: '2026-Q4',
  start: Date,   // first instant of the pick, in the zone
  end: Date,     // the instant just after it: filter with start <= t && t < end
  zone: 'Europe/Paris',
  text: 'T4 2026',
}

So a query for a quarter, a week or a range needs no date arithmetic.

The period block ​

mode: 'period' is one block for the date filter of a dashboard or a report. The reader chooses the kind of period on a tab (day, week, month, quarter, year, or a free range), then the period. Whatever the tab, the value is a first and a last day. Your query does not change.

js
createDatePicker('#period', {
  mode: 'period',
  granularities: ['month', 'quarter', 'year', 'custom'], // the tabs, in order; default: all six
  granularity: 'quarter',                                // the tab to start on, without a value
  compare: true,                                         // the reader chooses what to compare with
  onChange: ({ value, granularity, start, end, compare }) => {
    // value: { start: '2026-10-01', end: '2026-12-31' }, granularity: 'quarter'
    // compare: { with: 'previousYear', start: Date, end: Date, value: { start: '2025-10-01', end: '2025-12-31' } }
  },
});
  • With a value, the block opens on the tab that fits it: a whole month opens the month tab, 1 October to 31 December opens the quarter tab.
  • The pick stays when the tab changes. 4 December becomes December on the month tab, then 2026 on the year tab.
  • A ready-made period goes to its tab: "Last year" opens the year tab, "Last 7 days" the free range.
  • compare is true (the reader chooses), 'previousYear', 'previousPeriod' or 'none'. The same period last year keeps the days of the month. The previous period has as many days, just before.
  • Under a text field, the panel has an Apply button: the reader can change tab and comparison before closing.

Orientation ​

orientation: 'vertical' puts the ready-made periods above the calendar and stacks the months. Use it in a side panel or a narrow column. The default, horizontal, puts the periods beside the calendar and the months side by side. Below 520 px wide, the panel stacks by itself.

js
createDatePicker('#side', { mode: 'range', presets: true, orientation: 'vertical' });

Time zones ​

zone is local (default), UTC, or an IANA name such as Europe/Paris or Africa/Tunis. The picker uses the zone data of the browser. It ships none.

  • "Today" is today in the zone, not on the device.
  • A day is 23 or 25 hours long when the clock changes. start and end are right on those days.
  • With time: true, the value carries the offset of the zone at that instant: +01:00 in winter, +02:00 in summer, Z for UTC.
  • An hour that does not exist (spring change) moves forward. An hour that comes twice (autumn change) takes the first one.

zones shows a list in the panel. When the reader changes the zone, the instant stays and the clock moves: 14:30 in Paris becomes 22:30 in Tokyo.

js
createDatePicker('#call', { time: true, zone: 'Europe/Paris', zones: ['Europe/Paris', 'UTC', 'Asia/Tokyo'] });

A value with an offset, or a Date, is an instant. The picker reads it in its zone. A value without an offset is a wall clock in the zone.

Languages ​

locale is a BCP 47 tag: fr, de-CH, pt-BR, ar-TN. Without it, the picker takes the language of the page, then of the browser.

Month names, day names, digits, the first day of the week and the 12 or 24 hour clock come from the browser, for every language it knows. The words of the picker (Today, Clear, This quarter) are written in 28 languages: English, French, German, Spanish, Italian, Portuguese, Dutch, Swedish, Danish, Norwegian, Finnish, Polish, Czech, Slovak, Hungarian, Romanian, Bulgarian, Greek, Croatian, Slovenian, Ukrainian, Russian, Turkish, Catalan, Lithuanian, Latvian, Estonian and Arabic. Arabic reads right to left, and the arrow keys follow.

Replace any word, or add a language:

js
createDatePicker('#d', { locale: 'fr', labels: { clear: 'Vider', periods: { last7: 'Semaine glissante' } } });

Options ​

OptionDefaultWhat it does
modedateSee the table of modes.
timefalsePick the hour too, for date and range.
secondsfalseShow seconds.
minuteStep1Step of the minutes field.
hour12the locale12-hour clock with AM and PM.
valueThe value, or a Date.
zonelocalTime zone.
zonesZones the reader can switch between.
localethe pageLanguage and habits.
labelsReplace words of the picker.
firstDaythe locale0 Monday to 6 Sunday.
min, maxFirst and last day that can be picked.
disableA list of dates, or (date, weekday) => boolean.
months1, 2 for a rangeMonths side by side, 1 to 3.
weekNumbersfalseISO week numbers.
presetsfalsetrue for the usual periods, or your list, for range.
granularities, granularityall six, the one that fitsTabs of the period mode, and the tab to start on.
compareperiod mode: true, 'previousYear', 'previousPeriod' or 'none'.
orientationhorizontalvertical stacks the periods and the months.
inlineAlways open, in the page.
autoClosetrueClose when the pick is complete.
placeholderText of the empty field.
accentAccent colour.
themeautolight, dark or auto.
formatIntl options, or (selection) => text.
classExtra classes on the panel.
onChange, onOpen, onCloseYour functions.

The picker gives getValue(), getSelection(), setValue(value), update(options), open(), close(), toggle() and destroy(). update changes anything while the picker is open: language, zone, mode, limits, colours.

Periods ​

The ready-made periods are today, yesterday, last7, last30, thisWeek, lastWeek, thisMonth, lastMonth, thisQuarter, lastQuarter, thisYear, lastYear and yearToDate. Choose some, and add your own:

js
createDatePicker('#report', {
  mode: 'range',
  presets: ['last30', 'thisQuarter', 'yearToDate', { label: 'Fiscal year', range: (today) => ['2026-07-01', '2027-06-30'] }],
});

In a form ​

When the text field has a name, the form receives the ISO value under that name. The field keeps the text the reader sees. A range is sent as JSON.

Keyboard ​

KeyDoes
Arrow down, Enteropens the panel from the field
Arrowsone day, or one week up and down
Home, Endfirst and last day of the week
Page up, Page downone month
Shift + Page up, Page downone year
Enter, Spacepicks
Escapecloses and goes back to the field

The panel is a dialog, the calendar is a grid, and each day has its full date as a name for screen readers.

Look ​

Everything is a CSS variable on .nv-dt. Set them in your stylesheet, or pass accent for the main colour.

css
.nv-dt {
  --nv-dt-accent: #0c7a6b;      /* picked days, buttons */
  --nv-dt-accent-ink: #fff;     /* text on the accent */
  --nv-dt-bg: #fff;
  --nv-dt-ink: #1b1f24;
  --nv-dt-muted: #6b7480;       /* day names, other months */
  --nv-dt-line: #e3e6ea;
  --nv-dt-hover: #f1f3f5;
  --nv-dt-range: rgba(12, 122, 107, .14); /* days between the two ends */
  --nv-dt-radius: 10px;
  --nv-dt-cell: 36px;           /* size of a day */
  --nv-dt-font: inherit;
  --nv-dt-shadow: 0 10px 30px rgba(0, 0, 0, .14);
}

theme: 'auto' follows prefers-color-scheme, a dark class on the root element, or data-theme="dark". The classes are stable: .nv-dt-day, .is-today, .is-on, .is-start, .is-end, .is-in, .nv-dt-presets, .nv-dt-time, .nv-dt-foot. The stylesheet is added to the page by itself. It is also a file, @nervure/datetime/style.css, and a text, pickerCss, for a shadow root or a strict CSP.

On a server ​

The package can be imported on a server: nothing touches the DOM until createDatePicker runs. The calendar helpers work everywhere: period('lastQuarter', today('Europe/Paris'), 0), isoWeek, monthGrid, instant, wallClock.

Questions ​

Does it need a date library? ​

No. The calendar arithmetic is in the package, and time zones, month names and digits come from the Intl API of the browser. There is no dependency, and no zone data to update.

How do I get a date for my database? ​

Use selection.start and selection.end. They are Date instants in the time zone of the picker, and end is excluded: WHERE created_at >= :start AND created_at < :end is right for a day, a week, a quarter or a range, on days when the clock changes too.

Can the reader type a date? ​

Yes, in ISO form: 2026-12-04, 2026-W49, 2026-Q4, 14:30. A date that does not exist or that is closed is refused, and the field shows the last valid pick again.

How do I change the first day of the week? ​

It follows the language: Monday in France, Sunday in the United States, Saturday in Egypt. Set firstDay (0 Monday to 6 Sunday) to force it. The week mode always starts on Monday, as ISO 8601 says.

Does it work with Symfony, Laravel, Svelte or Angular? ​

Yes, through the web component. <nv-datetime name="start"> in a Twig or Blade form sends the ISO value under that name. Svelte and Angular use the same tag.

Is it accessible? ​

The panel is a dialog, the calendar is a grid, each day has its full date as a name, and tabs and periods say whether they are selected. Everything works with the keyboard. Colours can be set to meet your contrast needs.