How date/time ranges work in timescape
mainTo implement a date/time range (e.g., for booking systems), you use two separate timescape instances: one for the start (from) and one for the end (to).
In framework integrations (like React), you use the useTimescapeRange hook. This hook provides a from and to object, each containing its own input helpers and ampm object. It also provides a root props helper to manage focus and accessibility for the entire range.
In vanilla JavaScript, you can link two TimescapeManager instances using the marry function. This creates a relationship where from acts as the minimum bound and to acts as the maximum bound. It also enables focus wrapping between the two instances (e.g., moving past the last field of from focuses the first field of to).
import { useTimescapeRange } from "timescape/react";
import { useState } from "react";
const [fromDate, setFromDate] = useState(new Date("2000-01-01"));
const [toDate, setToDate] = useState(new Date());
const { getRootProps, from, to } = useTimescapeRange({
from: {
date: fromDate,
onDateChange: setFromDate,
},
to: {
date: toDate,
onDateChange: setToDate,
},
});
return (
<div {...getRootProps()}>
<div
<input {...from.getInputProps("days")} />
<span>/</span
<input {...from.getInputProps("months")} />
<span>/</span
<input {...from.getInputProps("years")} />
</div>
<div
<input {...to.getInputProps("days")} />
<span>/</span
<input {...to.getInputProps("months")} />
<span>/</span
<input {...to.getInputProps("years")} />
</div>
</div>
);