1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Rename subsecond_fraction_digits option to time_precision

This commit is contained in:
Andrew White 2014-01-26 20:39:16 +00:00
parent ef17225173
commit e3c382e3d6
4 changed files with 10 additions and 8 deletions

View file

@ -4,7 +4,7 @@ require 'active_support/core_ext/module/delegation'
module ActiveSupport module ActiveSupport
class << self class << self
delegate :use_standard_json_time_format, :use_standard_json_time_format=, delegate :use_standard_json_time_format, :use_standard_json_time_format=,
:subsecond_fraction_digits, :subsecond_fraction_digits=, :time_precision, :time_precision=,
:escape_html_entities_in_json, :escape_html_entities_in_json=, :escape_html_entities_in_json, :escape_html_entities_in_json=,
:encode_big_decimal_as_string, :encode_big_decimal_as_string=, :encode_big_decimal_as_string, :encode_big_decimal_as_string=,
:json_encoder, :json_encoder=, :json_encoder, :json_encoder=,
@ -106,9 +106,9 @@ module ActiveSupport
# as a safety measure. # as a safety measure.
attr_accessor :escape_html_entities_in_json attr_accessor :escape_html_entities_in_json
# Configures the inclusion of subsecond resolution when serializing instances # Sets the precision of encoded time values.
# of ActiveSupport::TimeWithZone. # Defaults to 3 (equivalent to millisecond precision)
attr_accessor :subsecond_fraction_digits attr_accessor :time_precision
# Sets the encoder used by Rails to encode Ruby objects into JSON strings # Sets the encoder used by Rails to encode Ruby objects into JSON strings
# in +Object#to_json+ and +ActiveSupport::JSON.encode+. # in +Object#to_json+ and +ActiveSupport::JSON.encode+.

View file

@ -154,7 +154,7 @@ module ActiveSupport
# # => "2005/02/01 05:15:10 -1000" # # => "2005/02/01 05:15:10 -1000"
def as_json(options = nil) def as_json(options = nil)
if ActiveSupport::JSON::Encoding.use_standard_json_time_format if ActiveSupport::JSON::Encoding.use_standard_json_time_format
digits = ActiveSupport::JSON::Encoding.subsecond_fraction_digits || 3 digits = ActiveSupport::JSON::Encoding.time_precision || 3
xmlschema(digits) xmlschema(digits)
else else
%(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}) %(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)})

View file

@ -466,15 +466,15 @@ EXPECTED
end end
end end
def test_twz_to_json_with_custom_subsecond_resolution def test_twz_to_json_with_custom_time_precision
with_standard_json_time_format(true) do with_standard_json_time_format(true) do
ActiveSupport::JSON::Encoding.subsecond_fraction_digits = 0 ActiveSupport::JSON::Encoding.time_precision = 0
zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone) time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone)
assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(time) assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(time)
end end
ensure ensure
ActiveSupport::JSON::Encoding.subsecond_fraction_digits = nil ActiveSupport::JSON::Encoding.time_precision = nil
end end
def test_twz_to_json_when_wrapping_a_date_time def test_twz_to_json_when_wrapping_a_date_time

View file

@ -441,6 +441,8 @@ There are a few configuration options available in Active Support:
* `config.active_support.use_standard_json_time_format` enables or disables serializing dates to ISO 8601 format. Defaults to `true`. * `config.active_support.use_standard_json_time_format` enables or disables serializing dates to ISO 8601 format. Defaults to `true`.
* `config.active_support.time_precision` sets the precision of JSON encoded time values. Defaults to `3`.
* `ActiveSupport::Logger.silencer` is set to `false` to disable the ability to silence logging in a block. The default is `true`. * `ActiveSupport::Logger.silencer` is set to `false` to disable the ability to silence logging in a block. The default is `true`.
* `ActiveSupport::Cache::Store.logger` specifies the logger to use within cache store operations. * `ActiveSupport::Cache::Store.logger` specifies the logger to use within cache store operations.