TimeConverter

Constants

Methods

.convert_type

def convert_type
  Time
end

.converted?

def converted?(value)
  value.is_a?(db_type)
end

.db_type

def db_type
  Integer
end
.primitive_type

ActiveAttr, which assists with property management, does not recognize Time as a valid type. We tell it to interpret it as Integer, as it will be when saved to the database.

def primitive_type
  Integer
end
.to_db

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

def to_db(value)
  if value.class == Date
    Time.utc(value.year, value.month, value.day, 0, 0, 0).to_i
  else
    value.utc.to_i
  end
end

.to_ruby

def to_ruby(value)
  Time.at(value).utc
end