formatDistanceToNowStrict
API index · Input types and conventions · Installation
formatDistanceToNowStrict(value, options?) → string
Use formatDistanceStrict's units, rounding, and suffix options against a fresh clock reading. Zone requirements are the same as formatDistanceToNow; the zone determines today's date for plain inputs.
Examples assume immediate evaluation after creating each value.
import { formatDistanceToNowStrict } from '@frantss/temporal-fns';
const future = Temporal.Now.instant().add({ minutes: 5 });
formatDistanceToNowStrict(future, {
timeZone: 'UTC',
unit: 'minute',
addSuffix: true,
}); // => 'in 5 minutes'
const past = Temporal.Now.zonedDateTimeISO('UTC').subtract({ hours: 2 });
formatDistanceToNowStrict(past, { unit: 'hour', addSuffix: true }); // => '2 hours ago'
const tomorrow = Temporal.Now.plainDateISO('UTC').add({ days: 1 });
formatDistanceToNowStrict(tomorrow, { timeZone: 'UTC', unit: 'day' }); // => '1 day'Related: formatDistanceStrict, formatDistanceToNow, formatRelative.
Behaviors: REL-015: ToNow supports all four relative kinds in an explicit clock context; REL-018: The viewing zone determines today's date for a plain ToNow input; REL-019: ToNow requires an explicit zone for plain and instant values; REL-027: Strict ToNow calls retain explicit units and rounding; REL-030: A ToNow zone override changes the calendar-day context for a zoned input; RNG-011: ToNow retains boundary support in explicit UTC context.