Guide of the date and time picker
Install
npm install @nervure/datetimeOr one file from a CDN. It registers <nv-datetime> and gives window.nervureDateTime:
<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.
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
<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
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
<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.
| Mode | The reader picks | Value |
|---|---|---|
date | one day | 2026-12-04 |
date with time: true | one day and an hour | 2026-12-04T14:30+01:00 |
range | a first and a last day | { start: '2026-12-01', end: '2026-12-31' } |
multiple | several days | ['2026-12-04', '2026-12-11'] |
week | an ISO week | 2026-W49 |
month | a month | 2026-12 |
quarter | a quarter | 2026-Q4 |
year | a year | 2026 |
time | a time of day | 14:30 |
period | a 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:
{
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.
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.
compareistrue(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.
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.
startandendare right on those days. - With
time: true, the value carries the offset of the zone at that instant:+01:00in winter,+02:00in summer,Zfor 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.
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:
createDatePicker('#d', { locale: 'fr', labels: { clear: 'Vider', periods: { last7: 'Semaine glissante' } } });Options
| Option | Default | What it does |
|---|---|---|
mode | date | See the table of modes. |
time | false | Pick the hour too, for date and range. |
seconds | false | Show seconds. |
minuteStep | 1 | Step of the minutes field. |
hour12 | the locale | 12-hour clock with AM and PM. |
value | The value, or a Date. | |
zone | local | Time zone. |
zones | Zones the reader can switch between. | |
locale | the page | Language and habits. |
labels | Replace words of the picker. | |
firstDay | the locale | 0 Monday to 6 Sunday. |
min, max | First and last day that can be picked. | |
disable | A list of dates, or (date, weekday) => boolean. | |
months | 1, 2 for a range | Months side by side, 1 to 3. |
weekNumbers | false | ISO week numbers. |
presets | false | true for the usual periods, or your list, for range. |
granularities, granularity | all six, the one that fits | Tabs of the period mode, and the tab to start on. |
compare | period mode: true, 'previousYear', 'previousPeriod' or 'none'. | |
orientation | horizontal | vertical stacks the periods and the months. |
inline | Always open, in the page. | |
autoClose | true | Close when the pick is complete. |
placeholder | Text of the empty field. | |
accent | Accent colour. | |
theme | auto | light, dark or auto. |
format | Intl options, or (selection) => text. | |
class | Extra classes on the panel. | |
onChange, onOpen, onClose | Your 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:
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
| Key | Does |
|---|---|
| Arrow down, Enter | opens the panel from the field |
| Arrows | one day, or one week up and down |
| Home, End | first and last day of the week |
| Page up, Page down | one month |
| Shift + Page up, Page down | one year |
| Enter, Space | picks |
| Escape | closes 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.
.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.