import { Component } from '@angular/core';
import { WrRelativeTime, wrFormatRelativeTime } from 'ngwr/pipes';
@Component({ imports: [WrRelativeTime] })
export class MyComponent {}wrRelativeTime
Say how far a date is from now in the app locale: "5 minutes ago", "tomorrow".
Installation
Import the class. This entry point has no stylesheet.
Basic usage
The pipe writes through Intl.RelativeTimeFormat in LOCALE_ID and reads a value as wrDate does.
{{ comment.createdAt | wrRelativeTime }} <!-- "5 minutes ago" -->
{{ task.dueAt | wrRelativeTime }} <!-- "in 3 hours" -->
{{ order.paidAt | wrRelativeTime: { numeric: 'always' } }} <!-- "1 day ago" -->
{{ comment.createdAt | wrRelativeTime: { style: 'narrow' } }} <!-- "5m ago" -->Units
The unit follows the distance. The count is cut, not rounded: 119 seconds is one minute. A year is 365 days and a month a twelfth of it. A date-only string is compared with today as a day.
Playground
5 minutes ago
{{ value | wrRelativeTime: { numeric: 'auto', style: 'long' } }}Customize
Distance
In the future
Numeric
Style
Live text
The pipe does not update by itself: it is pure, so the text stands until its value or options change. Date Stamp with relative keeps it current on a timer.
<!-- Stays current: re-renders on a timer -->
<wr-date-stamp [value]="comment.createdAt" relative />
<!-- Or move the reference instant yourself -->
{{ comment.createdAt | wrRelativeTime: { now: clock() } }}In TypeScript
wrFormatRelativeTime gives the same text for a string built in code, in the locale you pass.
import { wrFormatRelativeTime } from 'ngwr/pipes';
const now = new Date('2026-11-12T12:00:00Z');
wrFormatRelativeTime('2026-11-12T11:55:00Z', 'en-GB', { now }); // "5 minutes ago"
wrFormatRelativeTime('2026-11-11T12:00:00Z', 'en-GB', { now }); // "yesterday"
wrFormatRelativeTime('2026-11-12T15:00:00Z', 'ru', { now }); // "через 3 часа"
wrFormatRelativeTime(row.createdAt, 'en-GB'); // from the current timeAPI
| Name | Description | Type | Default |
|---|---|---|---|
wrRelativeTime | How far the value is from now, through Intl.RelativeTimeFormat in LOCALE_ID. Reads a Date, an epoch number or a string, as wrDate does, under the epochUnit and zonelessIn of withDates(). null, undefined, a blank string and a value that is not a date give an empty string. | (value: Date | string | number | null | undefined, options?: WrRelativeTimeOptions) => string | - |
wrFormatRelativeTime | The pipe as a function, in the locale given. It reads no app setting: a number is milliseconds. | (value: Date | string | number | null | undefined, locale: string, options?: WrRelativeTimeOptions) => string | - |
options.now | The instant the value is measured from. | Date | number | the current time |
options.numeric | auto lets the language say "yesterday", "tomorrow" and "now". always keeps the number. | 'auto' | 'always' | 'auto' |
options.style | How much of the unit is written, as Intl.RelativeTimeFormat reads it. | 'long' | 'short' | 'narrow' | 'long' |
options.epochUnit, zonelessIn, timeZone | How the value is read, as the last argument of wrDate says it. | WrParseDateOptions | `withDates()` in the pipe |