@eroyeroy/utils - v0.1.0
    Preparing search index...

    Function formatRelativeTime

    • Formats a date relative to now as a human-readable string (e.g. "2 hours ago").

      Parameters

      • date: Date

        The date to describe.

      • now: Date = ...

        Reference point. Defaults to new Date().

      Returns string

      const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000)
      formatRelativeTime(fiveMinutesAgo) // => "5 minutes ago"

      const tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000)
      formatRelativeTime(tomorrow) // => "in 1 day"