Sha256: 6fc67cdfb23f26b793ba6d80eb9f1ab5fb02123029e52967c42da3eb7fa90d27

Contents?: true

Size: 912 Bytes

Versions: 6

Compression:

Stored size: 912 Bytes

Contents

module Parliament
  module Grom
    module Decorator
      module Helpers
        # Namespace for date helper methods
        module DateHelper
          # Format start_date and end_date into a readable string
          # @param [String] date_format a string that represents the format we want to use for the date
          # @example Format a node with an end_date with the date format YYYY-MM-DD
          #   "grom_node_instance.date_range('%Y-%m-%d)" #=> "2010-01-01 to 2015-01-01"
          def date_range(date_format: '%-d %B %Y')
            return I18n.t('date_unavailable') if start_date.nil?
            if end_date
              "#{I18n.l(start_date, format: date_format)} #{I18n.t('to')} #{I18n.l(end_date, format: date_format)}"
            else
              "#{I18n.l(start_date, format: date_format)} #{I18n.t('to_present')}"
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
parliament-grom-decorators-0.29.0 lib/parliament/grom/decorator/helpers/date_helper.rb
parliament-grom-decorators-0.27.7 lib/parliament/grom/decorator/helpers/date_helper.rb
parliament-grom-decorators-0.27.6 lib/parliament/grom/decorator/helpers/date_helper.rb
parliament-grom-decorators-0.27.5 lib/parliament/grom/decorator/helpers/date_helper.rb
parliament-grom-decorators-0.27.4 lib/parliament/grom/decorator/helpers/date_helper.rb
parliament-grom-decorators-0.27.3 lib/parliament/grom/decorator/helpers/date_helper.rb