Module: Decidim::FriendlyDates

Extended by:
ActiveSupport::Concern
Included in:
Comments::Comment, Messaging::Message
Defined in:
decidim-core/lib/decidim/friendly_dates.rb

Overview

A concern to render friendlier dates

Instance Method Summary collapse

Instance Method Details

#friendly_created_atObject

Returns the creation date in a friendly relative format.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'decidim-core/lib/decidim/friendly_dates.rb', line 12

def friendly_created_at
  current_datetime = Time.current

  if created_at > current_datetime.beginning_of_day
    I18n.l(created_at, format: :time_of_day)
  elsif created_at > current_datetime.beginning_of_week
    I18n.l(created_at, format: :day_of_week)
  elsif created_at > current_datetime.beginning_of_year
    I18n.l(created_at, format: :day_of_month)
  else
    I18n.l(created_at, format: :day_of_year)
  end
end