Module: Koi::DateHelper
- Defined in:
- app/helpers/koi/date_helper.rb
Instance Method Summary collapse
-
#days_ago_in_words(value) ⇒ Object
Returns a string representing the number of days ago or from now.
Instance Method Details
#days_ago_in_words(value) ⇒ Object
Returns a string representing the number of days ago or from now. If the date is not ‘recent’ returns nil.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/helpers/koi/date_helper.rb', line 7 def days_ago_in_words(value) from_time = value.to_time to_time = Date.current.to_time distance_in_days = ((to_time - from_time) / (24.0 * 60.0 * 60.0)).round case distance_in_days when 0 "today" when 1 "yesterday" when -1 "tomorrow" when 2..5 "#{distance_in_days} days ago" when -5..-2 "#{distance_in_days.abs} days from now" end end |