rooks
Version:
Collection of awesome react hooks
44 lines (43 loc) • 1.52 kB
TypeScript
import type { Temporal } from "@js-temporal/polyfill";
type TemporalAgeOptions = {
/**
* The birth or start date from which the age is calculated.
* Accepts a Temporal.PlainDate, an ISO 8601 date string (YYYY-MM-DD),
* or a PlainDateLike object.
*/
date: Temporal.PlainDate | string;
/**
* The calendar system to use.
* @default "iso8601"
*/
calendar?: string;
/**
* The time zone used to determine "today".
* Defaults to the system time zone.
*/
timeZone?: string;
};
type TemporalAgeResult = {
/** Full calendar duration since the given date (years, months, days). */
duration: Temporal.Duration;
/** Convenience: the whole number of completed years. */
years: number;
/** Convenience: the remaining months after whole years. */
months: number;
/** Convenience: the remaining days after whole months. */
days: number;
};
/**
* useTemporalAge
* Returns the calendar age (years, months, days) from a given birth or
* start date, updating automatically at each day boundary.
*
* On the server this hook returns null so hydration remains deterministic.
* Returns null while the Temporal polyfill is loading.
*
* @param options Configuration with a date and optional time zone
* @see https://rooks.vercel.app/docs/hooks/useTemporalAge
*/
declare function useTemporalAge(options: TemporalAgeOptions): TemporalAgeResult | null;
export { useTemporalAge };
export type { TemporalAgeOptions, TemporalAgeResult };