Class: Neo4j::Shared::TypeConverters::TimeConverter

Inherits:
BaseConverter
  • Object
show all
Defined in:
lib/neo4j/shared/type_converters.rb

Class Method Summary collapse

Methods inherited from BaseConverter

converted?, #supports_array?

Class Method Details

.convert_typeObject



200
201
202
# File 'lib/neo4j/shared/type_converters.rb', line 200

def convert_type
  Time
end

.db_typeObject



204
205
206
# File 'lib/neo4j/shared/type_converters.rb', line 204

def db_type
  Integer
end

.to_db(value) ⇒ Object

Converts the given DateTime (UTC) value to an Integer. Only utc times are supported !



210
211
212
213
214
215
216
# File 'lib/neo4j/shared/type_converters.rb', line 210

def to_db(value)
  if value.class == Date
    Time.utc(value.year, value.month, value.day, 0, 0, 0).to_i
  else
    value.utc.to_i
  end
end

.to_ruby(value) ⇒ Object



218
219
220
# File 'lib/neo4j/shared/type_converters.rb', line 218

def to_ruby(value)
  Time.at(value).utc
end