Sha256: f889ad4960e0ea57416c4d25d7e98697668b7032cb6bfa54462f8a43342bc3ae
Contents?: true
Size: 534 Bytes
Versions: 1
Compression:
Stored size: 534 Bytes
Contents
module Compel module Coercion class DateTime < Type def coerce! format = options[:format] || '%FT%T' if value.is_a?(::DateTime) @value = value.strftime(format) end coerced = ::DateTime.strptime(value, format) if coerced.strftime(format) == value return coerced end fail rescue raise \ Compel::TypeError, "'#{value}' is not a parsable datetime with format: #{format}" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
compel-0.2.0 | lib/compel/coercion/datetime.rb |