Class: Neo4j::TypeConverters::DateTimeConverter

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

Overview

Converts DateTime objects to and from Java long types. Must be timezone UTC.

Class Method Summary collapse

Class Method Details

.convert?(clazz_or_symbol) ⇒ Boolean

Returns:

  • (Boolean)


212
213
214
# File 'lib/neo4j/type_converters/type_converters.rb', line 212

def convert?(clazz_or_symbol)
  DateTime == clazz_or_symbol || :datetime == clazz_or_symbol
end

.index_asObject



233
234
235
# File 'lib/neo4j/type_converters/type_converters.rb', line 233

def index_as
  Fixnum
end

.to_java(value) ⇒ Object

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



218
219
220
221
222
223
224
225
# File 'lib/neo4j/type_converters/type_converters.rb', line 218

def to_java(value)
  return nil if value.nil?
  if value.class == Date
    Time.utc(value.year, value.month, value.day, 0, 0, 0).to_i
  else
    Time.utc(value.year, value.month, value.day, value.hour, value.min, value.sec).to_i
  end
end

.to_ruby(value) ⇒ Object



227
228
229
230
231
# File 'lib/neo4j/type_converters/type_converters.rb', line 227

def to_ruby(value)
  return nil if value.nil?
  t = Time.at(value).utc
  DateTime.civil(t.year, t.month, t.day, t.hour, t.min, t.sec)
end