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 161 def convert_type 162 DateTime 163 end
db_type()
click to toggle source
# File lib/neo4j/shared/type_converters.rb 165 def db_type 166 Integer 167 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 171 def to_db(value) 172 value = value.new_offset(0) if value.respond_to?(:new_offset) 173 174 args = [value.year, value.month, value.day] 175 args += (value.class == Date ? [0, 0, 0] : [value.hour, value.min, value.sec]) 176 177 Time.utc(*args).to_i 178 end
to_ruby(value)
click to toggle source
# File lib/neo4j/shared/type_converters.rb 180 def to_ruby(value) 181 return value if value.is_a?(DateTime) 182 t = case value 183 when Time 184 return value.to_datetime.utc 185 when Integer 186 Time.at(value).utc 187 when String 188 return value.to_datetime 189 else 190 fail ArgumentError, "Invalid value type for DateType property: #{value.inspect}" 191 end 192 193 DateTime.civil(t.year, t.month, t.day, t.hour, t.min, t.sec) 194 end