Search code examples
datetimeruby-on-rails-4

Rails ActiveSupport::TimeWithZone as_json date format issue


I'm producing an API in rails, where some of the responses include a date. In my database, the fields are setup as datetime fields, which rails then turns into ActiveSupport::TimeWithZone objects. When I respond to a request with a datetime in, I expect to get something like

2013-07-23T01:18:32Z 

But instead, I'm getting

2013-07-23T01:18:32.000Z

Why is there the additional .000 at the end? As right now this is breaking the code on the client I'm writing. Obviously I could fix the client by changing the format it is expecting, but I'd like to know why rails is doing this in the first place, as the documentation suggests it shouldn't have the .000 there.


Solution

  • Looks like it's a change in Rails 4

    https://github.com/rails/rails/blob/master/activesupport/lib/active_support/time_with_zone.rb#L157

    Seems the API docs need updating :(