Class: FreshBooks::XmlSerializer::DateTimeSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/freshbooks/xml_serializer/serializers.rb

Overview

FreshBooks datetimes are specified in gmt-4. This library assumes utc and will convert to the appropriate timezone.

Class Method Summary collapse

Class Method Details

.to_node(member_name, value) ⇒ Object


97
98
99
100
101
# File 'lib/freshbooks/xml_serializer/serializers.rb', line 97

def self.to_node(member_name, value)
  element = REXML::Element.new(member_name)
  element.text = (value.utc + time_offset.to_i.hours).to_s(:db) # hack to convert to gmt-4, any better way?
  element
end

.to_value(xml_val) ⇒ Object


103
104
105
106
107
108
# File 'lib/freshbooks/xml_serializer/serializers.rb', line 103

def self.to_value(xml_val)
  DateTime.parse(xml_val.text.to_s + " #{time_offset}").utc # hack to convert from gmt-4 to utc
rescue ArgumentError => e
  # Sometimes freshbooks gives dates that look like this 0000-00-00 00:00:00
  nil
end