Class: ContentBlockTools::Presenters::FieldPresenters::TimePeriod::TimePresenter

Inherits:
BasePresenter
  • Object
show all
Defined in:
lib/content_block_tools/presenters/field_presenters/time_period/time_presenter.rb

Constant Summary

Constants inherited from BasePresenter

BasePresenter::BASE_TAG_TYPE

Instance Attribute Summary

Attributes inherited from BasePresenter

#field

Instance Method Summary collapse

Methods inherited from BasePresenter

#initialize

Constructor Details

This class inherits a constructor from ContentBlockTools::Presenters::FieldPresenters::BasePresenter

Instance Method Details

#renderObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/content_block_tools/presenters/field_presenters/time_period/time_presenter.rb', line 6

def render
  return unless field.present?

  time = Time.parse(field)
  hour = time.strftime("%H")
  minute = time.strftime("%M")

  if minute == "00"
    return "midday" if hour == "12"
    return "midnight" if hour == "00"

    return time.strftime("%l%P").strip
  end

  time.strftime("%l:%M%P").strip
end