Joe Essey Joe Essey - 1 year ago 63
Ruby Question

How to compare json parsed time with ruby object time?

I have some controller tests and I want to check the response values. I am unable to compare

with the following stack trace:

expected: 2016-09-17 10:50:00.000000000 +0000
got: "2016-09-17T10:50:00.000Z"

I tried a bunch of parsing techniques but they either return different formats, or do not return accurate values. Is there a simple way to get these values in to the same format to compare equality?

Answer Source

You're trying to compare two different data types. The parsed JSON is a string. The foo.start_time attribute is a Ruby datetime.

Do the following:


That will convert the string into a datetime, which can then be compared to foo.start_time.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download