Skip to content
On this page

RelativeTime

  • Beta
  • Not reviewed for accessibility
On this page

Formats a timestamp as a localized string or as relative text that auto-updates in the user's browser.

Arguments

NameTypeDefaultDescription
datetimeTimeN/AThe time to be formatted.
tenseSymbol:autoWhich tense to use. One of :auto, :future, or :past.
prefixsringnilWhat to prefix the relative ime display with.
secondSymbolSECOND_DEFAULTWhat format seconds should take. One of nil, :numeric, or :two_digit.
minuteSymbolMINUTE_DEFAULTWhat format minues should take. One of nil, :numeric, or :two_digit.
hourSymbolHOUR_DEFAULTWhat format hours should take. One of nil, :numeric, or :two_digit.
weekdaySymbolWEEKDAY_DEFAULTWhat format weekdays should take. One of nil, :long, :narrow, or :short.
daySymbolDAY_DEFAULTWhat format days should take. One of nil, :numeric, or :two_digit.
monthSymbolMONTH_DEFAULTWhat format months should take. One of nil, :long, :narrow, :numeric, :short, or :two_digit.
yearSymbolYEAR_DEFAULTWhat format years should take. One of nil, :numeric, or :two_digit.
time_zone_nameSymbolTIMEZONENAME_DEFAULTWhat format the time zone should take. One of nil, :long, :long_generic, :long_offset, :short, :short_generic, or :short_offset.
thresholdstringnilThe threshold, in ISO-8601 'durations' format, at which relative time displays become absolute.
precisionSymbolPRECISION_DEFAULTThe precision elapsed time should display. One of nil, :day, :hour, :minute, :month, :second, or :year.
formatSymbolnilThe format the display should take. One of :auto, :elapsed, or :micro.
format_styleSymbolnilThe format the display should take. One of nil, :long, :narrow, or :short.
langstringnilThe language to use.
titlestringnilProvide a custom title to the element.
system_argumentsHashN/ASystem arguments

Examples

Default

November 28, 1989 05:00
<%= render(Primer::Beta::RelativeTime.new(datetime: Time.at(628232400))) %>

Past Time

November 28, 1989 05:00
<%= render(Primer::Beta::RelativeTime.new(datetime: Time.at(628232400), tense: :past)) %>

Elapsed Time

November 28, 1989 05:00
<%= render(Primer::Beta::RelativeTime.new(datetime: Time.at(628232400), format: :elapsed)) %>