Ruby format of DateTime object #68

Closed
RKelln opened this Issue Feb 13, 2013 · 9 comments

Projects

None yet

3 participants

RKelln commented Feb 13, 2013

Sorry, I haven't had time to properly make a test case but I'm pretty sure I'm seeing some strangeness when converting ruby DateTime to json using the mode :compat and time_format: :ruby options. Instead of a string it always outputs a json DateTime object.

Owner
ohler55 commented Feb 14, 2013

Here is what I get. What are you seeing?

Oj.dump(DateTime.now(), mode: :compat, time_format: :ruby)
=> ""2013-02-13T15:02:02-08:00""

RKelln commented Feb 14, 2013

Thanks for the quick reply. I'm getting things like:

$ script/console
>> Oj.dump(DateTime.now(), mode: :compat, time_format: :ruby)
=> "{\"json_class\":\"DateTime\",\"y\":2013,\"m\":2,\"d\":14,\"H\":0,\"M\":14,\"S\":56,\"of\":\"-5/24\",\"sg\":2299161}"
>> Oj.dump(Time.now(), mode: :compat, time_format: :ruby)
=> "\"2013-02-14 00:20:08 -0500\""

$ gem list
    ....
    json (1.7.7, 1.7.6, 1.7.3, 1.4.6)
    json_builder (3.1.7, 3.1.3)
    json_pure (1.4.6)
    multi_json (1.5.0, 1.3.6)
    oj (2.0.4)
    rails (2.3.17)

What would be the difference? Should I try master branch?

Owner
ohler55 commented Feb 14, 2013

That looks like the object mode. I get the same result with Time and DateTime. What hardware are you one?

I get the same result in ruby 1.8.7 but not in 1.9.3

1.8.7 :001 > Oj.dump(DateTime.now(), :mode => :compat, :time_format => :ruby)
 => "{\"year\":2013,\"month\":2,\"day\":15,\"hour\":17,\"min\":50,\"sec\":53,\"offset\":{\"numerator\":-1,\"denominator\":3},\"start\":2299161}"
1.9.3p327 :004 > Oj.dump(DateTime.now(), mode: :compat, time_format: :ruby)
 => "\"2013-02-15T17:49:28-08:00\"" 

Unfortunately, we still have some things using 1.8.7 so this is inconvenient.

Owner
ohler55 commented Feb 16, 2013

Got it. 1.8.7 has the issue. I was also able to recreate the problem. I suspect it is due to the difference in the way 1.8.7 and 1.9.3 implement DateTime. I'll get the bug fixed in an upcoming release next week or this weekend.

Awesome! Thank you

Owner
ohler55 commented Mar 1, 2013

Did the 2.0.5 release and subsequent releases fix your problem?

Yes. Fixed for me. Thank you!

Owner
ohler55 commented Mar 1, 2013

Great, thanks.

@ohler55 ohler55 closed this Mar 1, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment