JimboTwice
JimboTwice

Reputation: 117

Comparing values of Ruby XMLRPC datetime returned from API to normal Ruby DateTime object

I have an XMLRPC datetime returned from a remote API, and I want to perform normal comparison operations to a standard Ruby datetime object, such as >, <, >=, etc. I've read that XMLRPC has some strange datetime restrictions (such as it doesn't support values before or after a certain date) and using DateTime.parse() for the returned object doesn't work, with or without string interpolation.

How do you accurately convert an XMLRPC::DateTime object to a standard Ruby 2.2.2 DateTime object so I can execute comparisons, regardless of the date returned?

Upvotes: 0

Views: 81

Answers (1)

Jean Meyer
Jean Meyer

Reputation: 409

Please convert everything into epoch_in_seconds

(XMLRPC::DateTime instance).to_time.to_i

(DateTime instance).to_i

You can also convert everything in UTC to make sure you're working with the same timezone

Upvotes: 1

Related Questions