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



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

def convert_type
  Time
end

.db_typeObject



207
208
209
# File 'lib/neo4j/shared/type_converters.rb', line 207

def db_type
  Integer
end

.to_db(value) ⇒ Object

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



213
214
215
216
217
218
219
# File 'lib/neo4j/shared/type_converters.rb', line 213

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



221
222
223
# File 'lib/neo4j/shared/type_converters.rb', line 221

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