This guide will show you how to upgrade from the now deprecated
Primer::TimeAgoComponent
to the latest Primer::Beta::RelativeTime
component.
Use of the TimeAgoComponent
component can be migrated with only a few minor changes.
For example, if the TimeAgoComponent
was set up in this way:
<%= render(Primer::TimeAgoComponent.new(time: Time.at(628232400))) %>
It can be migrated by renaming time
to datetime
, and adding the tense:
:past
setting.
<%= render(Primer::Beta::RelativeTime.new(datetime: Time.at(628232400), tense: :past)) %>
The majority of options available in RelativeTime
are not relevant when
using it as a replacement for TimeAgo
. There are a few changes that need to be
noted, however.
From Primer::TimeAgoComponent | To Primer::Beta::RelativeTime | Notes |
---|---|---|
time | datetime | Renamed argument, but the semantics remain the same |
micro | format: :micro | Instead of a boolean flag, set the format argument to the value of :micro |
n/a | tense: :past | Required for displaying how long ago the set time was. This argument tells RelativeTime to behave like TimeAgo did. |
The remaining arguments for RelativeTime
can be found in the documentation for
that component.
Please see the following for complete descriptions and examples.