Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

TimeWithZone#to_json should include time zone

#175

This patch includes the time zone information in the json representation for two reasons: consistency and usefulness.

Consistency: DateTime includes the zone, whereas Time does not:

>> Time.zone.now.to_json
=> "\"2008-05-13T01:47:35Z\""
>> Time.zone.now.to_datetime.to_json
=> "\"2008-05-12T18:47:42-07:00\""

Usefulness: Without including the zone offset, there is no way to figure out what zone the time was intended to be in. You can always figure out UTC (and any other offset) but determining the original is impossible.

Reported by Daniel Morrison · May 13th, 2008 @ 03:05 AM

State: resolved
Milestone: none
Assigned to: Rick Rick
Importance: none

Activity

  1. Geoff Buesing
    Geoff Buesing
    • Assigned user set to Rick

    This is a good catch -- we should make the output of #to_json consistent across Time, DateTime, and TimeWithZone instances.

    The outstanding question is, is there a reason to output json times in UTC?

    In the changeset that added ActiveSupport.use_standard_json_time_format, Time is converted to UTC before being serialized, whereas DateTime is not:

    http://dev.rubyonrails.org/chang...

    ISO 8601 allows time zone offsets other than UTC:

    http://en.wikipedia.org/wiki/ISO...

    ...so I'm not sure why Time #to_json is outputting UTC right now.

    Rick?

    May 13th, 2008 @ 02:21 PM

  2. Daniel Morrison
    Daniel Morrison

    My thought is simply that including the offset gives you more meaningful data, and you can easily convert to UTC if you want it.

    May 13th, 2008 @ 03:22 PM

  3. Rick
    Rick

    I thought it was pretty common practice to use UTC. But if this is what the people want, then so be it!

    May 13th, 2008 @ 05:50 PM

  4. Rick
  5. Rick
    Rick
    • State changed from new to resolved

    May 13th, 2008 @ 05:53 PM