Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useTimeAgoIntl.md
1---2category: Time3---45# useTimeAgoIntl67Reactive time ago with i18n supported. Automatically update the time ago string when the time changes. Powered by `Intl.RelativeTimeFormat`.89## Usage1011```js12import { useTimeAgoIntl } from '@vueuse/core'1314const timeAgoIntl = useTimeAgoIntl(new Date(2021, 0, 1))15```1617## Non-Reactivity Usage1819In case you don't need the reactivity, you can use the `formatTimeAgo` function to get the formatted string instead of a Ref.2021```js22import { formatTimeAgoIntl } from '@vueuse/core'2324const timeAgoIntl = formatTimeAgoIntl(new Date(2021, 0, 1)) // string25```2627## Type Declarations2829```ts30type Locale = Intl.UnicodeBCP47LocaleIdentifier | Intl.Locale31export interface FormatTimeAgoIntlOptions {32/**33* The locale to format with34*35* @default undefined36* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#locales37*/38locale?: Locale39/**40* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#options41*/42relativeTimeFormatOptions?: Intl.RelativeTimeFormatOptions43/**44* Whether to insert spaces between parts.45*46* Ignored if `joinParts` is provided.47*48* @default true49*/50insertSpace?: boolean51/**52* Custom function to join the parts returned by `Intl.RelativeTimeFormat.formatToParts`.53*54* If provided, it will be used instead of the default join logic.55*/56joinParts?: (57parts: Intl.RelativeTimeFormatPart[],58locale?: Intl.UnicodeBCP47LocaleIdentifier | Intl.Locale,59) => string60/**61* Custom units62*/63units?: TimeAgoUnit[]64}65export interface UseTimeAgoIntlOptions<Controls extends boolean>66extends FormatTimeAgoIntlOptions, ConfigurableScheduler {67/**68* Expose more controls and the raw `parts` result.69*70* @default false71*/72controls?: Controls73/**74* Update interval in milliseconds, set 0 to disable auto update75*76* @deprecated Please use `scheduler` option instead77* @default 30_00078*/79updateInterval?: number80}81type UseTimeAgoReturn<Controls extends boolean = false> = Controls extends true82? {83timeAgoIntl: ComputedRef<string>84parts: ComputedRef<Intl.RelativeTimeFormatPart[]>85} & Pausable86: ComputedRef<string>87export interface TimeAgoUnit {88name: Intl.RelativeTimeFormatUnit89ms: number90}91/**92* A reactive wrapper for `Intl.RelativeTimeFormat`.93*/94export declare function useTimeAgoIntl(95time: MaybeRefOrGetter<Date | number | string>,96options?: UseTimeAgoIntlOptions<false>,97): UseTimeAgoReturn<false>98export declare function useTimeAgoIntl(99time: MaybeRefOrGetter<Date | number | string>,100options: UseTimeAgoIntlOptions<true>,101): UseTimeAgoReturn<true>102/**103* Non-reactive version of useTimeAgoIntl104*/105export declare function formatTimeAgoIntl(106from: Date,107options?: FormatTimeAgoIntlOptions,108now?: Date | number,109): string110/**111* Format parts into a string112*/113export declare function formatTimeAgoIntlParts(114parts: Intl.RelativeTimeFormatPart[],115options?: FormatTimeAgoIntlOptions,116): string117```118