Relative time

Relative time displays time in a way that is clear, concise, and accessible.

v0.36.1BetaNot reviewed for accessibility

Description

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

Arguments

NameTypeDefaultDescription
datetime
Time

N/A

The time to be formatted.

tense
Symbol

:auto

Which tense to use. One of :auto, :future, or :past.

prefix
String

nil

What to prefix the relative time display with.

second
Symbol

SECOND_DEFAULT

What format seconds should take. One of nil, :numeric, or :two_digit.

minute
Symbol

MINUTE_DEFAULT

What format minues should take. One of nil, :numeric, or :two_digit.

hour
Symbol

HOUR_DEFAULT

What format hours should take. One of nil, :numeric, or :two_digit.

weekday
Symbol

WEEKDAY_DEFAULT

What format weekdays should take. One of nil, :long, :narrow, or :short.

day
Symbol

DAY_DEFAULT

What format days should take. One of nil, :numeric, or :two_digit.

month
Symbol

MONTH_DEFAULT

What format months should take. One of nil, :long, :narrow, :numeric, :short, or :two_digit.

year
Symbol

YEAR_DEFAULT

What format years should take. One of nil, :numeric, or :two_digit.

time_zone_name
Symbol

TIMEZONENAME_DEFAULT

What format the time zone should take. One of nil, :long, :long_generic, :long_offset, :short, :short_generic, or :short_offset.

threshold
String

nil

The threshold, in ISO-8601 'durations' format, at which relative time displays become absolute.

precision
Symbol

PRECISION_DEFAULT

The precision elapsed time should display. One of nil, :day, :hour, :minute, :month, :second, or :year.

format
Symbol

nil

The format the display should take. One of :auto, :elapsed, or :micro.

format_style
Symbol

nil

The format the display should take. One of nil, :long, :narrow, or :short.

lang
String

nil

The language to use.

title
String

nil

Provide a custom title to the element.

no_title
Boolean

false

Removes the title attribute provided on the element by default.

system_arguments
Hash

N/A

Examples