UNPKG

@alessiofrittoli/date-utils

Version:

Lightweight TypeScript date utility functions library

25 lines (23 loc) 867 B
/** * Relative date format. * * @param date The Date to format. * @param locales The Intl.RelativeTimeFormat locale to use. Defaults to user locale. * * @link [Relative Date Internationalization In JavaScript](https://blog.webdevsimplified.com/2020-07/relative-time-format) * * @usage ```ts * const currentDate = new Date() * * formatRelativeTime( new Date().setMonth( currentDate.getMonth() - 2 ) ) * // 2 months ago * formatRelativeTime( new Date().setDate( currentDate.getDate() - 1 ) ) * // yesterday * formatRelativeTime( new Date().setDate( currentDate.getDate() - 9 ) ) * // last week * ``` * * @returns The relative time formatted date string. */ declare const formatRelativeTime: (date?: string | number | Date, locales?: string | string[], options?: Intl.RelativeTimeFormatOptions) => string | undefined; export { formatRelativeTime };