Time Range Picker

A simple and reusable component to work with or select a date or a range of dates.

Note: Consumer of this component can customize the labels for header, timezone, cancel button, save button and even error message via LocaleProvider

Examples

Usage with new API

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.Selected date range is from 13 Nov,2024 02:50 PM to 19 Nov,2024 02:50 PM.

Basic Usage

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.Selected date range is from 11/13/2024 to 11/19/2024.

States

Time Select
Disabled
Error
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.

Format String

Select...
open
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.Selected date range is from 11/13/2024 to 11/19/2024.

Single Month

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.Selected date range is from 11/13/2024 to 11/19/2024.

Overrides

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.Selected date range is from 11/13/2024 to 11/19/2024.

Date and Time Select Overrides

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.Selected date range is from 11/13/2024 to 11/19/2024.

Time Range Picker with localization

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.Selected date range is from 11/13/2024 to 11/19/2024.

Date constraints

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.Selected date range is from 11/22/2021 to 12/03/2021.

NOTE: the valid range is [minDate, maxDate) since the Calendar sets seconds and milliseconds on end time to 59.999. Consider a scenario where maxDate has the time 12:30:00.000 and user selects the same as End Time. It gets converted to 12:30:59.999 which violates maxDate. Thus, the valid range is not inclusive of maxDate.

ApiTable

Time Range Picker Props

NameTypeDefaultDescription
autoSizeInput
boolean
falseAdjusts the width according to value
clearable
boolean
falseAllows to clears value from input
disableTimezone
boolean
falseHides the time zone picker
disabled
boolean
falseRenders component in disabled state.
displayVariant
'default' | 'compact' | 'iconButton'
If compact, it tries to minimize the size of input, by showing minimal info about the range upfront
excludeDates
array
A list of dates to disable. Array<Date>
filterDate
function
A filter function (Date => boolean) that is called to check the disabled state of a day. If false is returned the day is considered to be disabled.
fixedHeight
boolean
Defines if 6 rows should always be displayed for all the months.
formatString
string
MM/dd/yyyyString format passed to date-fns.
intent
'default' | 'success' | 'warning' | 'error'
Defines the intent of the Input.
maxDate
date
A max date that is selectable.
minDate
date
A min date that is selectable.
monthsShown
number
A number of months rendered in the calendar.
onChange
function
Event handler that is called when any update is made to date either by selecting preset, directly selecting date from calendar or changing time.
onClose
function
A function () => {} that is called every time datepicker closes except when it closes due after submit.
onSubmit
function
Event handler that is called when user will press the save button
overrides
custom
Lets you customize all aspects of the component.
peekNextMonth
boolean
falseDefines if dates outside of the range of the current month are displayed.
placeholder
string
Input's placeholder.
showFullDateInSummary
boolean
falseIf true, will show the full date with preset in input.
showTimezoneInSummary
boolean
falseIf true shows timezone in input with date
size
'xs' | 'sm' | 'md'
Input's size. SPACIOUS | COMFORTABLE -> md, COMPACT -> xxxs, DEFAULT -> md
startOpen
boolean
If true, opens the dropdown when the time range picker mounts.
timeRangePresets
array
Array of objects, each containing property id, label and getTimeRangeLimits. getTimeRangeLimits function should return array of startDate and endDate.
timeSelect
boolean
falseRenders the time picker to select end time
timezone
string
System TimezoneCurrently selected timezone.
value
array
Currently selected date. Either Array of Date or string from the ids of timeRangePresets
variant
'default' | 'line'
Input's variant - default, line
weekStartsOn
number
Decides the start day of week. 0 indicates Sunday. This will depend on locale

You can check the implementation of the component for more details.

Time Range Picker exports

You can import this module like so:

import {TimeRangePicker} from 'spaceweb/time-range-picker'

It exports the following components or utility functions:

  • TimeRangePicker
  • convertDateFromSrcTzToTargetTz
  • convertDateFromSystemTzToTargetTz
  • convertDateFromTargetTzToSystemTz
  • formatSummaryValue
  • getDefaultTimeRangePresets
  • getSystemTzName