class Ardm::Property::EpochTime

Public Instance Methods

dump(value) click to toggle source
# File lib/ardm/property/epoch_time.rb, line 16
def dump(value)
  value.to_i if value
end
load(value) click to toggle source
# File lib/ardm/property/epoch_time.rb, line 8
def load(value)
  if value.kind_of?(::Numeric)
    ::Time.at(value.to_i)
  else
    value
  end
end
typecast(value) click to toggle source
# File lib/ardm/property/epoch_time.rb, line 20
def typecast(value)
  case value
    when ::Time               then value
    when ::Numeric, /\A\d+\z/ then ::Time.at(value.to_i)
    when ::DateTime           then datetime_to_time(value)
    when ::String             then ::Time.parse(value)
  end
end

Private Instance Methods

datetime_to_time(datetime) click to toggle source
# File lib/ardm/property/epoch_time.rb, line 31
def datetime_to_time(datetime)
  utc = datetime.new_offset(0)
  ::Time.utc(utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec)
end