Micro lib without any dependency for getting relative time
Switch branches/tags
Nothing to show
Clone or download
davydovanton Merge pull request #4 from dylanwolff/fix-article-used-for-single-hour
Use 'an' rather than 'a' as the article where the time difference is a single hour
Latest commit b5df021 Jul 7, 2017



Build Status Code Climate Test Coverage

Micro lib without any dependency for getting relative time.


I love rails but sometimes we need to create web apps (or CLI) without rails and AS. That's why I created #time_ago_in_words analog on pure ruby without any dependencies.


Add this line to your application's Gemfile:

gem 'relative_time'

And then execute:

$ bundle

Or install it yourself as:

$ gem install relative_time


Just call #in_words method with any time object:

RelativeTime.in_words(Time.now)          # => less than a minute

RelativeTime.in_words(Time.now - 1 * 60) # => a minute ago
RelativeTime.in_words(Time.now - 3 * 60) # => 3 minutes ago

RelativeTime.in_words(Time.now + 1 * 60) # => in a minute
RelativeTime.in_words(Time.now + 3 * 60) # => in 3 minutes

Also you can use second argument as a from date:

date_from = Time.now - 60 * 60 # one hour ago
RelativeTime.in_words(Time.now, date_from)          # => an hour ago

Supported intervals

  • minutes
  • hours
  • days
  • weeks
  • months
  • years


Bug reports and pull requests are welcome on GitHub at https://github.com/davydovanton/relative_time. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


The gem is available as open source under the terms of the MIT License.