compote-ui
Version:
An opinionated UI component library for Svelte, built on top of [Ark UI](https://ark-ui.com) with additional components and features not available in the core Ark UI library.
45 lines (44 loc) • 2.56 kB
TypeScript
import { CalendarDate, ZonedDateTime, type DateValue } from '@internationalized/date';
export type { DateValue };
/**
* Anything the date components accept for a single value: an
* `@internationalized/date` value, an ISO/DB string, a native `Date`, or null.
*/
export type DateInputValue = DateValue | string | Date | null | undefined;
/** The runtime shape a bound value was provided in, used to round-trip on change. */
export type DateValueShape = 'string' | 'date' | 'date-value';
/** Report the runtime shape of a value so a change can be emitted in the same shape. */
export declare function dateValueShape(value: DateInputValue): DateValueShape | null;
/**
* Coerce a string / `Date` / `DateValue` into a `DateValue` for Ark UI.
*
* String auto-detection:
* - `"2024-01-15"` → {@link parseDate} (date-only)
* - `"2024-01-15T10:30:00"` → {@link parseDateTime} (local datetime)
* - `"2024-01-15T10:30:00Z"` / `"…+02:00"` → zoned (in `timeZone`, else local)
*/
export declare function toDateValue(value: DateInputValue, timeZone?: string): DateValue | null;
/** Serialize a `DateValue` to an ISO string (absolute `…Z` for zoned values). */
export declare function dateValueToString(value: DateValue): string;
/** Convert a `DateValue` to a native `Date`. */
export declare function dateValueToDate(value: DateValue, timeZone?: string): Date;
/** Emit a `DateValue` back in the original `shape` it was bound as. */
export declare function fromDateValue(value: DateValue | null, shape: DateValueShape, timeZone?: string): DateValue | string | Date | null;
/**
* A value read for display in `timeZone`: a calendar date (a day, with no instant behind it)
* or an instant converted into `timeZone`.
*/
export type ZonedOrCalendarDate = CalendarDate | ZonedDateTime;
/**
* Read any date-ish value — a `DateValue`, ISO/DB string, native `Date` or epoch-millisecond
* number — the way it should be shown in `timeZone`. Never throws: anything unparseable
* (including an out-of-range date like `2024-02-30`) is `null`.
*
* - `"2024-03-15"` and `CalendarDate` stay calendar dates. They are never turned into an
* instant, which would put them on the previous day in zones west of UTC.
* - `Date`, epoch numbers, offset strings (`Z`, `+02:00`) and `ZonedDateTime` are instants,
* converted into `timeZone`.
* - A datetime without an offset (`"2024-03-15T10:30"`, `CalendarDateTime`) is a wall-clock
* time in `timeZone`.
*/
export declare function readDateInZone(value: unknown, timeZone: string): ZonedOrCalendarDate | null;