Timestamp Recipes

QScroller keeps the UI small and focused. @timestamp-js/core is the companion layer for date math, UTC persistence, interval snapping, and range validation when the selected values need to become application data.

Use the scroller for collection, then normalize the emitted value into a Timestamp before saving, comparing, or sending the value to an API.

Date-Time Storage


Range Validation


Calendar Adapters

QDateScroller, QDateRangeScroller, and QDateTimeScroller model dates in the active Timestamp calendar system. For native calendar systems such as Islamic Civil (Hijri), Indian National (Saka), Hebrew, or Persian, pass calendar-system; string, array, and object model values use that calendar’s native YYYY-MM-DD fields, while JavaScript Date values remain Gregorian interop values.

Install the adapter package you need beside @timestamp-js/core:

pnpm add @timestamp-js/core @timestamp-js/calendar-hebrew @timestamp-js/calendar-islamic @timestamp-js/calendar-saka @timestamp-js/calendar-persian
Calendar Adapter Scrollers


Store Instants Explicitly

QDateTimeScroller emits the same shape it received where possible. If your app stores instants in a database, normalize the emitted value, snap it if needed, and store Unix milliseconds.

import {
  function getDateTime(timestamp: Timestamp): string
Formats a Timestamp as date plus time.
@paramtimestamp Timestamp object to format.@returnsDate-time string such as `YYYY-MM-DD HH:mm`.@categoryconversion
getDateTime
,
function roundToInterval(timestamp: Timestamp, minutes: number): Timestamp
Rounds a Timestamp to the nearest interval.
@paramtimestamp Timestamp object to round.@paramminutes Interval size in minutes.@returnsRounded Timestamp.@categoryarithmetic
roundToInterval
,
function toUnixMilliseconds(timestamp: Timestamp): number
Converts a Timestamp into Unix milliseconds by reading its fields as UTC. This is deterministic across server and client runtimes. It does not read or convert the optional `timezone` suffix stored on the Timestamp.
@paramtimestamp Timestamp object to convert.@returnsUnix milliseconds.@categoryconversion
toUnixMilliseconds
,
function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | null
Converts a supported date or date-time string into a formatted Timestamp object. If `now` is supplied, the returned timestamp also includes relative flags such as `past`, `current`, `future`, and `currentWeekday`.
@paraminput Date or date-time string, such as `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like value with optional milliseconds and timezone suffix.@paramnow Optional Timestamp used to calculate relative flags.@returnsFormatted Timestamp object, or `null` when the input cannot be parsed.@categoryparsing
parseTimestamp
,
} from '@timestamp-js/core' const const input: Timestamp | nullinput = function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | null
Converts a supported date or date-time string into a formatted Timestamp object. If `now` is supplied, the returned timestamp also includes relative flags such as `past`, `current`, `future`, and `currentWeekday`.
@paraminput Date or date-time string, such as `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like value with optional milliseconds and timezone suffix.@paramnow Optional Timestamp used to calculate relative flags.@returnsFormatted Timestamp object, or `null` when the input cannot be parsed.@categoryparsing
parseTimestamp
('2036-06-08 09:37')
const const snapped: Timestamp | nullsnapped = const input: Timestamp | nullinput === null ? null : function roundToInterval(timestamp: Timestamp, minutes: number): Timestamp
Rounds a Timestamp to the nearest interval.
@paramtimestamp Timestamp object to round.@paramminutes Interval size in minutes.@returnsRounded Timestamp.@categoryarithmetic
roundToInterval
(const input: Timestampinput, 15)
const snapped: Timestamp | nullsnapped === null ? null : function getDateTime(timestamp: Timestamp): string
Formats a Timestamp as date plus time.
@paramtimestamp Timestamp object to format.@returnsDate-time string such as `YYYY-MM-DD HH:mm`.@categoryconversion
getDateTime
(const snapped: Timestampsnapped) // "2036-06-08 09:30"
const snapped: Timestamp | nullsnapped === null ? null : function toUnixMilliseconds(timestamp: Timestamp): number
Converts a Timestamp into Unix milliseconds by reading its fields as UTC. This is deterministic across server and client runtimes. It does not read or convert the optional `timezone` suffix stored on the Timestamp.
@paramtimestamp Timestamp object to convert.@returnsUnix milliseconds.@categoryconversion
toUnixMilliseconds
(const snapped: Timestampsnapped)

Validate Ranges Outside The Picker

QDateRangeScroller validates that the end date does not come before the start date. Domain validation, such as checking blackout windows, booking windows, or availability gaps, belongs in your app logic.

import {
  function createTimestampRange(start: Timestamp, end: Timestamp, useTime?: boolean): TimestampRange
Creates an inclusive Timestamp range and normalizes start/end order.
@paramstart First boundary.@paramend Second boundary.@paramuseTime Include time-of-day when ordering boundaries.@returnsFrozen inclusive Timestamp range.@categoryranges
createTimestampRange
,
function findRangeGaps(source: TimestampRange, occupied: TimestampRange[], useTime?: boolean): TimestampRange[]
Finds open gaps inside a source range after occupied ranges are removed. This is an alias for subtractRanges() with naming that reads naturally in booking, resource, and availability workflows.
@paramsource Source range.@paramoccupied Ranges that are not available.@paramuseTime Include time-of-day in the comparison.@returnsGap ranges.@categoryranges
findRangeGaps
,
function isRangeOverlapping(first: TimestampRange, second: TimestampRange, useTime?: boolean): boolean
Checks whether two inclusive TimestampRange values overlap.
@paramfirst First range.@paramsecond Second range.@paramuseTime Include time-of-day in the comparison.@returnsTrue when the ranges overlap.@categorycomparison
isRangeOverlapping
,
function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | null
Converts a supported date or date-time string into a formatted Timestamp object. If `now` is supplied, the returned timestamp also includes relative flags such as `past`, `current`, `future`, and `currentWeekday`.
@paraminput Date or date-time string, such as `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like value with optional milliseconds and timezone suffix.@paramnow Optional Timestamp used to calculate relative flags.@returnsFormatted Timestamp object, or `null` when the input cannot be parsed.@categoryparsing
parseTimestamp
,
} from '@timestamp-js/core' const const request: TimestampRangerequest = function createTimestampRange(start: Timestamp, end: Timestamp, useTime?: boolean): TimestampRange
Creates an inclusive Timestamp range and normalizes start/end order.
@paramstart First boundary.@paramend Second boundary.@paramuseTime Include time-of-day when ordering boundaries.@returnsFrozen inclusive Timestamp range.@categoryranges
createTimestampRange
(
function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | null
Converts a supported date or date-time string into a formatted Timestamp object. If `now` is supplied, the returned timestamp also includes relative flags such as `past`, `current`, `future`, and `currentWeekday`.
@paraminput Date or date-time string, such as `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like value with optional milliseconds and timezone suffix.@paramnow Optional Timestamp used to calculate relative flags.@returnsFormatted Timestamp object, or `null` when the input cannot be parsed.@categoryparsing
parseTimestamp
('2036-06-08 00:00')!,
function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | null
Converts a supported date or date-time string into a formatted Timestamp object. If `now` is supplied, the returned timestamp also includes relative flags such as `past`, `current`, `future`, and `currentWeekday`.
@paraminput Date or date-time string, such as `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like value with optional milliseconds and timezone suffix.@paramnow Optional Timestamp used to calculate relative flags.@returnsFormatted Timestamp object, or `null` when the input cannot be parsed.@categoryparsing
parseTimestamp
('2036-06-12 00:00')!,
) const const blackout: TimestampRangeblackout = function createTimestampRange(start: Timestamp, end: Timestamp, useTime?: boolean): TimestampRange
Creates an inclusive Timestamp range and normalizes start/end order.
@paramstart First boundary.@paramend Second boundary.@paramuseTime Include time-of-day when ordering boundaries.@returnsFrozen inclusive Timestamp range.@categoryranges
createTimestampRange
(
function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | null
Converts a supported date or date-time string into a formatted Timestamp object. If `now` is supplied, the returned timestamp also includes relative flags such as `past`, `current`, `future`, and `currentWeekday`.
@paraminput Date or date-time string, such as `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like value with optional milliseconds and timezone suffix.@paramnow Optional Timestamp used to calculate relative flags.@returnsFormatted Timestamp object, or `null` when the input cannot be parsed.@categoryparsing
parseTimestamp
('2036-06-14 00:00')!,
function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | null
Converts a supported date or date-time string into a formatted Timestamp object. If `now` is supplied, the returned timestamp also includes relative flags such as `past`, `current`, `future`, and `currentWeekday`.
@paraminput Date or date-time string, such as `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like value with optional milliseconds and timezone suffix.@paramnow Optional Timestamp used to calculate relative flags.@returnsFormatted Timestamp object, or `null` when the input cannot be parsed.@categoryparsing
parseTimestamp
('2036-06-17 00:00')!,
) function isRangeOverlapping(first: TimestampRange, second: TimestampRange, useTime?: boolean): boolean
Checks whether two inclusive TimestampRange values overlap.
@paramfirst First range.@paramsecond Second range.@paramuseTime Include time-of-day in the comparison.@returnsTrue when the ranges overlap.@categorycomparison
isRangeOverlapping
(const request: TimestampRangerequest, const blackout: TimestampRangeblackout) // false
function findRangeGaps(source: TimestampRange, occupied: TimestampRange[], useTime?: boolean): TimestampRange[]
Finds open gaps inside a source range after occupied ranges are removed. This is an alias for subtractRanges() with naming that reads naturally in booking, resource, and availability workflows.
@paramsource Source range.@paramoccupied Ranges that are not available.@paramuseTime Include time-of-day in the comparison.@returnsGap ranges.@categoryranges
findRangeGaps
(const request: TimestampRangerequest, [const blackout: TimestampRangeblackout]) // request is still open

Preserve UI Precision

QScroller date-time views are minute-focused today. Timestamp can still parse, store, and format seconds and milliseconds for API payloads, audit values, or background scheduling state.

import { function makeDateTimeUTC(timestamp: Timestamp): Date
Converts a Timestamp date and time into a UTC JavaScript Date.
@paramtimestamp Timestamp object to convert.@returnsJavaScript Date object built with `Date.UTC()`.@categoryconversion
makeDateTimeUTC
, function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | null
Converts a supported date or date-time string into a formatted Timestamp object. If `now` is supplied, the returned timestamp also includes relative flags such as `past`, `current`, `future`, and `currentWeekday`.
@paraminput Date or date-time string, such as `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like value with optional milliseconds and timezone suffix.@paramnow Optional Timestamp used to calculate relative flags.@returnsFormatted Timestamp object, or `null` when the input cannot be parsed.@categoryparsing
parseTimestamp
} from '@timestamp-js/core'
const const timestamp: Timestamp | nulltimestamp = function parseTimestamp(input: string, now?: Timestamp | null): Timestamp | null
Converts a supported date or date-time string into a formatted Timestamp object. If `now` is supplied, the returned timestamp also includes relative flags such as `past`, `current`, `future`, and `currentWeekday`.
@paraminput Date or date-time string, such as `YYYY-MM-DD`, `YYYY-MM-DD HH:mm:ss`, or an ISO-like value with optional milliseconds and timezone suffix.@paramnow Optional Timestamp used to calculate relative flags.@returnsFormatted Timestamp object, or `null` when the input cannot be parsed.@categoryparsing
parseTimestamp
('2036-06-08T09:30:15.250Z')
const timestamp: Timestamp | nulltimestamp?.Timestamp.second?: number | undefined
Optional second of the minute.
second
// 15
const timestamp: Timestamp | nulltimestamp?.Timestamp.millisecond?: number | undefined
Optional millisecond of the second.
millisecond
// 250
const timestamp: Timestamp | nulltimestamp === null ? null : function makeDateTimeUTC(timestamp: Timestamp): Date
Converts a Timestamp date and time into a UTC JavaScript Date.
@paramtimestamp Timestamp object to convert.@returnsJavaScript Date object built with `Date.UTC()`.@categoryconversion
makeDateTimeUTC
(const timestamp: Timestamptimestamp).Date.toISOString(): string
Returns a date as a string value in ISO format.
toISOString
()