class Neo4j::Shared::TypeConverters::DateTimeConverter
Converts DateTime objects to and from Java long types. Must be timezone UTC.
Public Class Methods
convert_type()
click to toggle source
# File lib/neo4j/shared/type_converters.rb 164 def convert_type 165 DateTime 166 end
db_type()
click to toggle source
# File lib/neo4j/shared/type_converters.rb 168 def db_type 169 Integer 170 end
to_db(value)
click to toggle source
Converts the given DateTime (UTC) value to an Integer. DateTime values are automatically converted to UTC.
# File lib/neo4j/shared/type_converters.rb 174 def to_db(value) 175 value = value.new_offset(0) if value.respond_to?(:new_offset) 176 177 args = [value.year, value.month, value.day] 178 args += (value.class == Date ? [0, 0, 0] : [value.hour, value.min, value.sec]) 179 180 Time.utc(*args).to_i 181 end
to_ruby(value)
click to toggle source
# File lib/neo4j/shared/type_converters.rb 183 def to_ruby(value) 184 return value if value.is_a?(DateTime) 185 t = case value 186 when Time 187 return value.to_datetime.utc 188 when Integer 189 Time.at(value).utc 190 when String 191 return value.to_datetime 192 else 193 fail ArgumentError, "Invalid value type for DateType property: #{value.inspect}" 194 end 195 196 DateTime.civil(t.year, t.month, t.day, t.hour, t.min, t.sec) 197 end