Moving Away From Primer::TimeAgoComponent

This guide will show you how to upgrade from the now deprecated Primer::TimeAgoComponent to the latest Primer::Beta::RelativeTime component.

A Migration Example

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)) %>

Arguments

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::TimeAgoComponentTo Primer::Beta::RelativeTimeNotes
timedatetimeRenamed argument, but the semantics remain the same
microformat: :microInstead of a boolean flag, set the format argument to the value of :micro
n/atense: :pastRequired 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.

 

Back to development docs