提交 28ab79d7 编写于 作者: J James Harton

Modify TimeWithZone#as_json to return 3DP of sub-second accuracy by default,...

Modify TimeWithZone#as_json to return 3DP of sub-second accuracy by default, since it's allowed by the spec and is very useful.
上级 162f7c1e
## Rails 4.0.0 (unreleased) ##
* Modify `TimeWithZone#as_json` to include 3 decimal places of sub-second accuracy
by default, which is optional as per the ISO8601 spec, but extremely useful. Also
the default behaviour of Date#toJSON() in recent versions of Chrome, Safari and
Firefox.
* Improve `String#squish` to handle Unicode whitespace. *Antoine Lyset*
* Standardise on `to_time` returning an instance of `Time` in the local system timezone
......
......@@ -154,7 +154,7 @@ def xmlschema(fraction_digits = 0)
# # => "2005/02/01 15:15:10 +0000"
def as_json(options = nil)
if ActiveSupport::JSON::Encoding.use_standard_json_time_format
xmlschema
xmlschema(3)
else
%(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)})
end
......
......@@ -75,7 +75,7 @@ def test_to_json_with_use_standard_json_time_format_config_set_to_false
def test_to_json_with_use_standard_json_time_format_config_set_to_true
old, ActiveSupport.use_standard_json_time_format = ActiveSupport.use_standard_json_time_format, true
assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(@twz)
assert_equal "\"1999-12-31T19:00:00.000-05:00\"", ActiveSupport::JSON.encode(@twz)
ensure
ActiveSupport.use_standard_json_time_format = old
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册