Class: DataMapper::Types::EpochTime

Inherits:
DataMapper::Type show all
Defined in:
lib/gems/dm-types-0.9.9/lib/dm-types/epoch_time.rb

Constant Summary

Constants inherited from DataMapper::Type

DataMapper::Type::PROPERTY_OPTIONS, DataMapper::Type::PROPERTY_OPTION_ALIASES

Class Method Summary collapse

Methods inherited from DataMapper::Type

bind, configure, inherited, options, primitive

Class Method Details

.dump(value, property) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/gems/dm-types-0.9.9/lib/dm-types/epoch_time.rb', line 15

def self.dump(value, property)
  case value
  when Integer
    value
  when Time
    value.to_i
  when DateTime
    Time.parse(value.to_s).to_i
  end
end

.load(value, property) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/gems/dm-types-0.9.9/lib/dm-types/epoch_time.rb', line 6

def self.load(value, property)
  case value
  when Integer
    Time.at(value)
  else
    value
  end
end