Class: FacebookAds::FieldTypes::MyDateTime

Inherits:
Base
  • Object
show all
Defined in:
lib/facebook_ads/field_types/datetime.rb

Instance Method Summary collapse

Methods included from FacebookAds::FieldTypes

#for, #lookup, #register

Instance Method Details

#deserialize(value, session = nil) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/facebook_ads/field_types/datetime.rb', line 26

def deserialize(value, session = nil)
  case value
    when String
      ::DateTime.strptime(value, '%FT%T%:z')
    else
      ::Time.at(value).to_datetime
  end
end

#serialize(value) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/facebook_ads/field_types/datetime.rb', line 35

def serialize(value)
  case value
    when ::DateTime, ::Time
      value.to_time.to_i
    when ::String
      DateTime.parse(value).to_time.to_i
    else
      value
  end
end