Date adapters
The calendar never formats, computes or even reads dates itself: an adapter does. Its date type
is the one the calendar takes and gives: Date with the date-fns, Day.js and Luxon adapters,
Temporal.ZonedDateTime with the Temporal one.
| Adapter | Date type | Time zone | Peer dependency |
|---|---|---|---|
@weekwise/adapter-date-fns |
Date |
the browser’s | date-fns |
@weekwise/adapter-dayjs |
Date |
the browser’s | dayjs |
@weekwise/adapter-luxon |
Date |
any IANA zone | luxon 3.4+ |
@weekwise/adapter-temporal |
Temporal.ZonedDateTime |
any IANA zone | none |
import { DateFnsAdapter } from "@weekwise/adapter-date-fns";import { fr } from "date-fns/locale/fr";
const adapter = new DateFnsAdapter({ locale: fr });import { DayjsAdapter } from "@weekwise/adapter-dayjs";import fr from "dayjs/locale/fr";
const adapter = new DayjsAdapter({ locale: fr });import { LuxonAdapter } from "@weekwise/adapter-luxon";
const adapter = new LuxonAdapter({ locale: "fr", timeZone: "Europe/Paris" });import { TemporalAdapter } from "@weekwise/adapter-temporal";
const adapter = new TemporalAdapter({ locale: "fr", timeZone: "Europe/Paris" });Give the adapter to the UI package: <DateLocalizationProvider adapter={adapter}> in React,
createCalendar(element, { adapter }) in the DOM package.
Formats
Section titled “Formats”Every adapter has built-in patterns you can override in its own tokens:
new DateFnsAdapter({ locale: zhCN, formats: { timeShort: "HH:mm", weekdayShort: "EEEEEE" } });| Pattern | Used for |
|---|---|
timeShort |
Hour labels, now line, drag preview |
date |
Drag preview |
weekdayShort |
Column headers, date picker |
dateTime, dateTimeShort, dateTimeLong, … |
Your own format(date, "dateTime") calls |
Temporal has no format strings, so its patterns are either Intl.DateTimeFormat options or
tokens (dd.MM.yyyy).
Your own adapter
Section titled “Your own adapter”Any object implementing DateAdapter<TDate> from @weekwise/core works. The calendar takes and
gives dates of that type and never looks inside them.
import type { DateAdapter } from "@weekwise/core";
export class MyAdapter implements DateAdapter<MyDate> { readonly locale = "en-GB"; // BCP 47 code: interface language and heading formats readonly weekStartsOn = 1; // default first day of the week readonly timeZone = "Europe/Berlin"; // optional IANA zone; omit for the runtime's zone toMillis(date: MyDate | number | string) { /* epoch ms: keys, sorting, timers */ } fromMillis(millis: number): MyDate { /* the date at epoch ms */ } // implement every other method of the interface}Methods take TDate | number | string (a timestamp or an ISO string) and return TDate.
Wall-clock methods (getHours, getStartOfDay, addDays…) work in the adapter’s time zone.
@weekwise/adapter-date-fns is a reference implementation for Date,
@weekwise/adapter-temporal for another date type and time zones.