Class: Extant::Coercers::DateTime

Inherits:
Base
  • Object
show all
Defined in:
lib/extant/coercers/date_time.rb

Constant Summary

Constants inherited from Base

Base::UncoercedValue

Instance Method Summary collapse

Methods inherited from Base

#coerced?, coercer_name, #initialize

Constructor Details

This class inherits a constructor from Extant::Coercers::Base

Instance Method Details

#coerceObject



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/extant/coercers/date_time.rb', line 3

def coerce
  if value.is_a?(::DateTime)
    self.coerced = true
    return value
  end

  result = ::DateTime.parse(value.to_s)
  self.coerced = true
  result
rescue ArgumentError
  UncoercedValue
end