@stanfordspezi/spezi-web-design-system
Version:
Stanford Biodesign Digital Health Spezi Web Design System
97 lines (96 loc) • 2.3 kB
TypeScript
import { Nil } from '../misc';
export type DateInput = Date | string | number;
export interface DateRange {
start?: Nil<DateInput>;
end?: Nil<DateInput>;
}
/**
* Formats date to include just the day, month and year.
* The exact date format is based on locale.
*
* @example
* ```ts
* // US format
* "2/12/2019"
* ```
*
* @example
* ```ts
* // PL format
* "12.02.2019"
* ```
*/
export declare const formatDate: (value: DateInput) => string;
/**
* Formats date like {@link formatDate}, but replaces Nil and empty strings with `null`.
*/
export declare const formatNilDate: (value: Nil<DateInput>) => string | null;
/**
* Formats date to include both day, month, year and hours, seconds.
* The exact date format is based on locale.
*
* @example
* ```ts
* // US format
* "2/12/2019 11:31 PM"
* ```
*
* @example
* ```ts
* // PL format
* "12.02.2019 23:31"
* ```
*/
export declare const formatDateTime: (value: DateInput) => string;
/**
* Formats date like {@link formatDateTime}, but replaces Nil and empty strings with `null`.
*/
export declare const formatNilDateTime: (value: Nil<DateInput>) => string | null;
/**
* Formats a date range into a human-readable string using locale-aware formatting.
*
* @example
* ```ts
* // Both dates provided
* formatDateRange({ start: "2025-01-01", end: "2025-01-31" })
* // Returns: "1/1/2025 – 1/31/2025"
* ```
*
* @example
* ```ts
* // Only start date
* formatDateRange({ start: "2025-01-01" })
* // Returns: "from 1/1/2025"
* ```
*
* @example
* ```ts
* // Only end date
* formatDateRange({ end: "2025-01-31" })
* // Returns: "ending 1/31/2025"
* ```
*
* @example
* ```ts
* // No dates provided
* formatDateRange({})
* // Returns: null
* ```
*/
export declare const formatDateRange: (dateRange: DateRange, formatter?: Intl.DateTimeFormat) => string | null;
/**
* Formats a date range like {@link formatDateRange}, but returns `null` for nil date ranges.
*
* @example
* ```ts
* formatNilDateRange({ start: "2025-01-01", end: "2025-01-31" })
* // Returns: "1/1/2025 – 1/31/2025"
* ```
*
* @example
* ```ts
* formatNilDateRange(null)
* // Returns: null
* ```
*/
export declare const formatNilDateRange: (dateRange: Nil<DateRange>, formatter?: Intl.DateTimeFormat) => string | null;