This project is archived and is in readonly mode.
TimeWithZone#to_json should include time zone
Reported by Daniel Morrison | May 13th, 2008 @ 03:05 AM
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.
Comments and changes to this ticket
-
Geoff Buesing May 13th, 2008 @ 02:21 PM
- 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?
-
Daniel Morrison May 13th, 2008 @ 03:22 PM
My thought is simply that including the offset gives you more meaningful data, and you can easily convert to UTC if you want it.
-
Rick May 13th, 2008 @ 05:50 PM
I thought it was pretty common practice to use UTC. But if this is what the people want, then so be it!
-
Rick May 13th, 2008 @ 05:53 PM
- State changed from new to resolved
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>