formatDistanceStrict
API index · Input types and conventions · Installation
formatDistanceStrict(value, base, options?) → string
Return a rounded count with one unit and no approximation wording. unit accepts second, minute, hour, day, month, or year. Without it, elapsed magnitude chooses the unit before rounding, at 60 seconds, 60 minutes, 24 hours, 30 days, and 365 days.
roundingMethod defaults to round and also accepts floor, ceil, or trunc. Rounding applies to the absolute magnitude; addSuffix uses the actual direction even when the rounded count is zero. addSuffix defaults to false and locale to en-US.
import { formatDistanceStrict } from '@frantss/temporal-fns';
const base = Temporal.PlainDateTime.from('2026-01-01T00:00');
formatDistanceStrict(base.add({ seconds: 3599 }), base); // => '60 minutes'
formatDistanceStrict(base.subtract({ seconds: 91 }), base, {
unit: 'minute',
roundingMethod: 'floor',
addSuffix: true,
}); // => '1 minute ago'
const zoned = Temporal.ZonedDateTime.from('2026-03-07T12:00[America/New_York]');
formatDistanceStrict(zoned.add({ days: 1 }), zoned, { unit: 'day' }); // => '1 day'
formatDistanceStrict(zoned.add({ days: 1 }), zoned, { unit: 'hour' }); // => '23 hours'Related: formatDistance, formatDistanceToNowStrict, formatDuration.
Behaviors: REL-004: Strict default units are chosen before rounding; REL-005: Strict rounding applies to the absolute magnitude; REL-007: Months and years use constrained calendar anniversaries; REL-008: Zoned days and elapsed hours carry different meanings across DST; REL-029: Rounding to zero does not erase the actual suffix direction; RNG-012: A failing original-year named-zone total retains its native error.