Module: Parliament::Grom::Decorator::Helpers::DateHelper

Overview

Namespace for date helper methods

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#date_range(date_format: '%-d %-B %Y') ⇒ Object

Format start_date and end_date into a readable string

Examples:

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"

Parameters:

  • date_format (String) (defaults to: '%-d %-B %Y')

    a string that represents the format we want to use for the date

Since:

  • 0.1.0



11
12
13
14
15
16
17
18
# File 'lib/parliament/grom/decorator/helpers/date_helper.rb', line 11

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