Sha256: d40ab2a6c3d573b05e0887a6b19cb7adfb7b0554ddb5479632c05425166b4601

Contents?: true

Size: 779 Bytes

Versions: 16

Compression:

Stored size: 779 Bytes

Contents

# frozen_string_literal: true

require "active_support/core_ext/date_time/calculations"
require "active_support/concern"

module Decidim
  # A concern to render friendlier dates
  module FriendlyDates
    extend ActiveSupport::Concern

    # Returns the creation date in a friendly relative format.
    def friendly_created_at
      current_datetime = Time.zone.now

      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
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
decidim-core-0.13.1 lib/decidim/friendly_dates.rb
decidim-core-0.12.2 lib/decidim/friendly_dates.rb
decidim-core-0.13.0 lib/decidim/friendly_dates.rb
decidim-core-0.12.1 lib/decidim/friendly_dates.rb
decidim-core-0.13.0.pre1 lib/decidim/friendly_dates.rb
decidim-core-0.12.0 lib/decidim/friendly_dates.rb
decidim-core-0.11.2 lib/decidim/friendly_dates.rb
decidim-core-0.12.0.pre lib/decidim/friendly_dates.rb
decidim-core-0.11.1 lib/decidim/friendly_dates.rb
decidim-core-0.11.0.pre1 lib/decidim/friendly_dates.rb
decidim-core-0.10.1 lib/decidim/friendly_dates.rb
decidim-core-0.10.0 lib/decidim/friendly_dates.rb
decidim-core-0.9.3 lib/decidim/friendly_dates.rb
decidim-core-0.9.2 lib/decidim/friendly_dates.rb
decidim-core-0.9.1 lib/decidim/friendly_dates.rb
decidim-core-0.9.0 lib/decidim/friendly_dates.rb