class Primer::Beta::RelativeTime

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

def call

def call
  render(Primer::BaseComponent.new(**@system_arguments).with_content(@datetime.strftime("%B %-d, %Y %H:%M")))
end

def initialize(

Parameters:
  • system_arguments (Hash) -- <%= link_to_system_arguments_docs %>
  • title (string) -- Provide a custom title to the element.
  • lang (string) -- The language to use.
  • format_style (Symbol) -- The format the display should take. <%= one_of(Primer::Beta::RelativeTime::FORMAT_STYLE_OPTIONS) %>
  • format (Symbol) -- The format the display should take. <%= one_of(Primer::Beta::RelativeTime::FORMAT_OPTIONS) %>
  • precision (Symbol) -- The precision elapsed time should display. <%= one_of(Primer::Beta::RelativeTime::PRECISION_OPTIONS) %>
  • threshold (string) -- The threshold, in ISO-8601 'durations' format, at which relative time displays become absolute.
  • time_zone_name (Symbol) -- What format the time zone should take. <%= one_of(Primer::Beta::RelativeTime::TIMEZONENAME_OPTIONS) %>
  • year (Symbol) -- What format years should take. <%= one_of(Primer::Beta::RelativeTime::YEAR_OPTIONS) %>
  • month (Symbol) -- What format months should take. <%= one_of(Primer::Beta::RelativeTime::MONTH_OPTIONS) %>
  • day (Symbol) -- What format days should take. <%= one_of(Primer::Beta::RelativeTime::DAY_OPTIONS) %>
  • weekday (Symbol) -- What format weekdays should take. <%= one_of(Primer::Beta::RelativeTime::WEEKDAY_OPTIONS) %>
  • hour (Symbol) -- What format hours should take. <%= one_of(Primer::Beta::RelativeTime::HOUR_OPTIONS) %>
  • minute (Symbol) -- What format minues should take. <%= one_of(Primer::Beta::RelativeTime::MINUTE_OPTIONS) %>
  • second (Symbol) -- What format seconds should take. <%= one_of(Primer::Beta::RelativeTime::SECOND_OPTIONS) %>
  • prefix (sring) -- What to prefix the relative ime display with.
  • tense (Symbol) -- Which tense to use. <%= one_of(Primer::Beta::RelativeTime::TENSE_OPTIONS) %>
  • datetime (Time) -- The time to be formatted.
def initialize(
  datetime:,
  tense: TENSE_DEFAULT,
  prefix: nil,
  second: SECOND_DEFAULT,
  minute: MINUTE_DEFAULT,
  hour: HOUR_DEFAULT,
  weekday: WEEKDAY_DEFAULT,
  day: DAY_DEFAULT,
  month: MONTH_DEFAULT,
  year: YEAR_DEFAULT,
  time_zone_name: TIMEZONENAME_DEFAULT,
  threshold: nil,
  precision: PRECISION_DEFAULT,
  format: nil,
  format_style: nil,
  lang: nil,
  title: nil,
  **system_arguments
)
  @system_arguments = deny_tag_argument(**system_arguments)
  @system_arguments[:tag] = "relative-time"
  @system_arguments[:tense] = tense if tense.present?
  @system_arguments[:prefix] = prefix if prefix.present?
  @system_arguments[:second] = fetch_or_fallback(SECOND_OPTIONS, second, SECOND_DEFAULT) if second.present?
  @system_arguments[:minute] = fetch_or_fallback(MINUTE_OPTIONS, minute, MINUTE_DEFAULT) if minute.present?
  @system_arguments[:hour] = fetch_or_fallback(HOUR_OPTIONS, hour, HOUR_DEFAULT) if hour.present?
  @system_arguments[:weekday] = fetch_or_fallback(WEEKDAY_OPTIONS, weekday, WEEKDAY_DEFAULT) if weekday.present?
  @system_arguments[:day] = fetch_or_fallback(DAY_OPTIONS, day, DAY_DEFAULT) if day.present?
  @system_arguments[:month] = fetch_or_fallback(MONTH_OPTIONS, month, MONTH_DEFAULT) if month.present?
  @system_arguments[:year] = fetch_or_fallback(YEAR_OPTIONS, year, YEAR_DEFAULT) if year.present?
  @system_arguments[:"time-zone-name"] = fetch_or_fallback(TIMEZONENAME_OPTIONS, time_zone_name, TIMEZONENAME_DEFAULT) if time_zone_name.present?
  @system_arguments[:threshold] = threshold if threshold.present?
  @system_arguments[:precision] = precision if precision.present?
  @system_arguments[:title] = title if title.present?
  @system_arguments[:lang] = lang if lang.present?
  @system_arguments[:format] = fetch_or_fallback(FORMAT_OPTIONS, format, FORMAT_DEFAULT) if format.present?
  @system_arguments[:"format-style"] = format_style if format_style.present?
  if datetime.present? && datetime.respond_to?(:iso8601)
    @datetime = datetime
    @system_arguments[:datetime] = datetime.iso8601
  elsif datetime.present?
    @datetime = Time.iso8601 datetime
    @system_arguments[:datetime] = @datetime
  end
end