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



14
15
16
17
18
19
20
21
# File 'lib/facebook_ads/field_types/datetime.rb', line 14

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



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

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