Class: Tempora::TimePeriodFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/tempora/formatter.rb

Defined Under Namespace

Classes: I18nScopeKeyFinder

Constant Summary collapse

I18nScopeKeys =
i(same_day same_month same_year different_year).freeze
I18nScopeKeysIdentifiers =
{ begin: :from, end: :till}

Instance Method Summary collapse

Constructor Details

#initialize(timeperiod, format: :long) ⇒ TimePeriodFormatter

format: [:default, :short, :long] -> see I18n.localize



7
8
9
10
# File 'lib/tempora/formatter.rb', line 7

def initialize(timeperiod, format: :long) 
  @timeperiod = timeperiod
  @format = format
end

Instance Method Details

#renderObject



12
13
14
15
16
# File 'lib/tempora/formatter.rb', line 12

def render
  from = I18n.l @timeperiod.begin, format: format_for(:from)
  till = I18n.l @timeperiod.end,   format: format_for(:till)
  [from, till].reject(&:empty?).join ' – '
end