date-vir - v7.3.2
    Preparing search index...

    Function toRelativeString

    • This function starts with a duration (either by being directly passed a duration or by diffing two dates into a duration) and converts that duration into a relative string like "1 month ago" or "in 1 month". Rounding is automatically set to 0 decimal points, but that can be changed.

      When extremely close to a 0 difference, the output string will be 'just now', which can be disabled.

      Parameters

      Returns string

      import {toRelativeString, selectAllDurationUnits} from 'date-vir';

      toRelativeString({days: 1.6}, {days: true}); // `'in 2 days'`
      toRelativeString({days: 1.6}, {days: true, hours: true}); // `'in 1 day, 14 hours'`
      toRelativeString({seconds: 1}, selectAllDurationUnits); // `'just now'`