class TableSchema::Types::DateTime
Public Class Methods
supported_constraints()
click to toggle source
# File lib/tableschema/types/datetime.rb, line 9 def self.supported_constraints [ 'required', 'unique', 'pattern', 'enum', 'minimum', 'maximum' ] end
Public Instance Methods
cast_any(value)
click to toggle source
# File lib/tableschema/types/datetime.rb, line 37 def cast_any(value) return value if value.is_a?(type) begin date = ::DateTime._parse(value) if date.values.count >= 4 ::DateTime.parse(value) else raise TableSchema::InvalidDateTimeType.new("#{value} is not a valid datetime") end rescue ArgumentError raise TableSchema::InvalidDateTimeType.new("#{value} is not a valid datetime") end end
cast_default(value)
click to toggle source
raw_formats = ['DD/MM/YYYYThh/mm/ss'] py_formats = ['%Y/%m/%dT%H:%M:%S'] format_map = dict(zip(raw_formats, py_formats))
# File lib/tableschema/types/datetime.rb, line 32 def cast_default(value) @format_string = iso8601 cast_fmt(value) end
cast_fmt(value)
click to toggle source
# File lib/tableschema/types/datetime.rb, line 52 def cast_fmt(value) return value if value.is_a?(type) begin return ::DateTime.strptime(value, @format_string) rescue ArgumentError raise TableSchema::InvalidDateTimeType.new("#{value} is not a valid date") end end
iso8601()
click to toggle source
# File lib/tableschema/types/datetime.rb, line 24 def iso8601 '%Y-%m-%dT%H:%M:%SZ' end
name()
click to toggle source
# File lib/tableschema/types/datetime.rb, line 5 def name 'datetime' end
type()
click to toggle source
# File lib/tableschema/types/datetime.rb, line 20 def type ::DateTime end