import { OpUnitType } from 'dayjs'; export type MongoDate = { $date: number | string; }; export type IsoDate = string; export type NumberDate = number; /** Date formats we are going to deal with. */ export type CoreDate = IsoDate | MongoDate | NumberDate | Date; /** * Custom React hook for date parsing, formatting, and localization. * * Provides utility functions to: * - Parse various date formats and timestamps into Dayjs objects, respecting the current language. * - Format dates in user-friendly ways, including "time ago", "yesterday", and localized date strings. * - Compute elapsed durations from a given date to now. * * @returns An object containing: * - `fromNow(date: CoreDate | NumberDate): string` — Returns a human-readable elapsed duration from the given date to now. * - `formatDate(date: CoreDate, format?: 'short' | 'long' | 'abbr' | string): string` — Formats a date according to the specified format and current language. * - `formatTimeAgo(date: CoreDate | NumberDate): string` — Returns a localized string representing how long ago the date was, with special handling for today, yesterday, and recent dates. * * @remarks * - Uses the current language from the Edifice client context for localization. */ export default function useDate(): { fromNow: (date: CoreDate) => string; formatDate: (date: CoreDate, format?: string) => string; formatTimeAgo: (date: CoreDate) => string; dateIsSame: (date: CoreDate, date2: CoreDate, unit?: OpUnitType) => boolean; dateIsSameOrAfter: (date: CoreDate, date2: CoreDate, unit?: OpUnitType) => boolean; dateIsToday: (date: CoreDate) => boolean; };