module FormatTime
Constants
- VERSION
Public Instance Methods
format_absolute_time(time)
click to toggle source
# File lib/format_time.rb, line 15 def format_absolute_time(time) return '-' if time.nil? Time.current.year == time.year ? in_year(time) : previous_year(time) end
format_relative_time(time)
click to toggle source
Your code goes hereā¦
# File lib/format_time.rb, line 9 def format_relative_time(time) return '-' if time.nil? distance_of_time_in_words_to_now(time, include_seconds: true) end
Private Instance Methods
in_year(time)
click to toggle source
# File lib/format_time.rb, line 23 def in_year(time) if time.today? format_relative_time(time) elsif time.to_date == Date.yesterday I18n.l(time, format: :yesterday) elsif time.to_date.cweek == Date.current.cweek I18n.l(time, format: :in_week) else I18n.l(time, format: :normal) end end
previous_year(time)
click to toggle source
# File lib/format_time.rb, line 35 def previous_year(time) I18n.l(time, format: :previous_year) end