ActionView: relative_time_in_words

Most Rails applications rely on the popular time_ago_in_words helper to show how much time has passed since an event. However, when dealing with future events or very recent dates, saying “in 20 hours” isn’t always the best way to communicate with a user.

PR #55405 introduces the relative_time_in_words helper, bringing much more natural language to our Views by handling dates as “today,” “yesterday,” or “tomorrow.”

The Problem: Lack of Daily Context

The time_ago_in_words helper focuses purely on time distance (minutes, hours, days). If a user has a trip scheduled for tomorrow, Rails might say “in about 20 hours.”

While technically correct, it’s not how humans speak. For a great user experience (UX), terms relative to the current day are much easier to process than performing mental calculations with hours.

The Solution: Native Natural Language

relative_time_in_words examines the date and decides the best way to describe it in relation to “now,” prioritizing terms like yesterday, today, and tomorrow when appropriate.

Examples:

1
2
3
4
5
6
7
8
9
10
11
12
13
# Assuming today is January 7, 2026

relative_time_in_words(Date.today) 
# => "today"

relative_time_in_words(Date.yesterday) 
# => "yesterday"

relative_time_in_words(Date.tomorrow) 
# => "tomorrow"

relative_time_in_words(2.days.ago) 
# => "2 days ago"

Why This Matters