Class: Neo4j::TypeConverters::DateTimeConverter
- Inherits:
-
Object
- Object
- Neo4j::TypeConverters::DateTimeConverter
- 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
- .convert?(clazz_or_symbol) ⇒ Boolean
- .index_as ⇒ Object
-
.to_java(value) ⇒ Object
Converts the given DateTime (UTC) value to an Fixnum.
- .to_ruby(value) ⇒ Object
Class Method Details
.convert?(clazz_or_symbol) ⇒ 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_as ⇒ Object
234 235 236 |
# File 'lib/neo4j/type_converters/type_converters.rb', line 234 def index_as Fixnum end |
.to_java(value) ⇒ Object
Converts the given DateTime (UTC) value to an Fixnum. DateTime values are automatically converted to UTC.
218 219 220 221 222 223 224 225 226 |
# File 'lib/neo4j/type_converters/type_converters.rb', line 218 def to_java(value) return nil if value.nil? value = value.new_offset(0) if value.respond_to?(:new_offset) 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
228 229 230 231 232 |
# File 'lib/neo4j/type_converters/type_converters.rb', line 228 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 |