Class: Blueprinter::DateTimeFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/blueprinter/formatters/date_time_formatter.rb

Constant Summary collapse

InvalidDateTimeFormatterError =
Class.new(BlueprinterError)

Instance Method Summary collapse

Instance Method Details

#format(value, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/blueprinter/formatters/date_time_formatter.rb', line 5

def format(value, options)
  return value if value.nil?

  field_format = options[:datetime_format]
  if value.respond_to?(:strftime)
    value = format_datetime(value, field_format)
  elsif field_format
    raise InvalidDateTimeFormatterError, 'Cannot format invalid DateTime object'
  end
  value
end