Skip to content

Commit 28ab79d

Browse files
committed
Modify TimeWithZone#as_json to return 3DP of sub-second accuracy by default, since it's allowed by the spec and is very useful.
1 parent 162f7c1 commit 28ab79d

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

activesupport/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Rails 4.0.0 (unreleased) ##
22

3+
* Modify `TimeWithZone#as_json` to include 3 decimal places of sub-second accuracy
4+
by default, which is optional as per the ISO8601 spec, but extremely useful. Also
5+
the default behaviour of Date#toJSON() in recent versions of Chrome, Safari and
6+
Firefox.
7+
38
* Improve `String#squish` to handle Unicode whitespace. *Antoine Lyset*
49

510
* Standardise on `to_time` returning an instance of `Time` in the local system timezone

activesupport/lib/active_support/time_with_zone.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def xmlschema(fraction_digits = 0)
154154
# # => "2005/02/01 15:15:10 +0000"
155155
def as_json(options = nil)
156156
if ActiveSupport::JSON::Encoding.use_standard_json_time_format
157-
xmlschema
157+
xmlschema(3)
158158
else
159159
%(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)})
160160
end

activesupport/test/core_ext/time_with_zone_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_to_json_with_use_standard_json_time_format_config_set_to_false
7575

7676
def test_to_json_with_use_standard_json_time_format_config_set_to_true
7777
old, ActiveSupport.use_standard_json_time_format = ActiveSupport.use_standard_json_time_format, true
78-
assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(@twz)
78+
assert_equal "\"1999-12-31T19:00:00.000-05:00\"", ActiveSupport::JSON.encode(@twz)
7979
ensure
8080
ActiveSupport.use_standard_json_time_format = old
8181
end

0 commit comments

Comments
 (0)