Skip to content

Latest commit

 

History

History
137 lines (56 loc) · 1.63 KB

TimeConverter.rst

File metadata and controls

137 lines (56 loc) · 1.63 KB

TimeConverter

Constants

Files

Methods

.call

ruby

def to_ruby(value)

Time.at(value).utc

end

.convert_type

ruby

def convert_type

Time

end

.db_type

ruby

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.

ruby

def primitive_type

Integer

end

.to_db

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

ruby

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

ruby

def to_ruby(value)

Time.at(value).utc

end