class ActiveGraph::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/active_graph/shared/type_converters.rb
139 def convert_type
140   DateTime
141 end
db_type() click to toggle source
    # File lib/active_graph/shared/type_converters.rb
143 def db_type
144   Integer
145 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/active_graph/shared/type_converters.rb
149 def to_db(value)
150   value = value.new_offset(0) if value.respond_to?(:new_offset)
151 
152   args = [value.year, value.month, value.day]
153   args += (value.class == Date ? [0, 0, 0] : [value.hour, value.min, value.sec])
154 
155   Time.utc(*args).to_i
156 end
to_ruby(value) click to toggle source
    # File lib/active_graph/shared/type_converters.rb
158 def to_ruby(value)
159   return value if value.is_a?(DateTime)
160   t = case value
161       when Time
162         return value.to_datetime.utc
163       when Integer
164         Time.at(value).utc
165       when String
166         return value.to_datetime
167       else
168         fail ArgumentError, "Invalid value type for DateType property: #{value.inspect}"
169       end
170 
171   DateTime.civil(t.year, t.month, t.day, t.hour, t.min, t.sec)
172 end