Sha256: fcb2e3e0db5b61fb61a22274d8c9a558fff838299cf749ef25a19dedc8e87c75

Contents?: true

Size: 812 Bytes

Versions: 13

Compression:

Stored size: 812 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # Helper to format date ranges
  module DateRangeHelper
    def format_date_range(start_date, end_date)
      return if [start_date, end_date].any?(&:blank?)

      format = [start_date.year, end_date.year].any? { |year| year != Date.current.year } ? :decidim_short_with_month_name_short : :decidim_with_month_name_short
      if start_date.to_date == end_date.to_date && start_date.to_time == end_date.to_time
        l(start_date.to_date, format:)
      elsif start_date.to_date == end_date.to_date
        "#{l(start_date.to_date, format:)} #{l(start_date, format: :time_of_day)} → #{l(end_date, format: :time_of_day)}".html_safe
      else
        "#{l(start_date.to_date, format:)} → #{l(end_date.to_date, format:)}".html_safe
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/helpers/decidim/date_range_helper.rb
decidim-core-0.28.4 app/helpers/decidim/date_range_helper.rb
decidim-core-0.29.0 app/helpers/decidim/date_range_helper.rb
decidim-core-0.28.3 app/helpers/decidim/date_range_helper.rb
decidim-core-0.29.0.rc4 app/helpers/decidim/date_range_helper.rb
decidim-core-0.29.0.rc3 app/helpers/decidim/date_range_helper.rb
decidim-core-0.29.0.rc2 app/helpers/decidim/date_range_helper.rb
decidim-core-0.29.0.rc1 app/helpers/decidim/date_range_helper.rb
decidim-core-0.28.2 app/helpers/decidim/date_range_helper.rb
decidim-core-0.28.1 app/helpers/decidim/date_range_helper.rb
decidim-core-0.28.0 app/helpers/decidim/date_range_helper.rb
decidim-core-0.28.0.rc5 app/helpers/decidim/date_range_helper.rb
decidim-core-0.28.0.rc4 app/helpers/decidim/date_range_helper.rb