Skip to content

Commit e3c382e

Browse files
committed
Rename subsecond_fraction_digits option to time_precision
1 parent ef17225 commit e3c382e

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

activesupport/lib/active_support/json/encoding.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
module ActiveSupport
55
class << self
66
delegate :use_standard_json_time_format, :use_standard_json_time_format=,
7-
:subsecond_fraction_digits, :subsecond_fraction_digits=,
7+
:time_precision, :time_precision=,
88
:escape_html_entities_in_json, :escape_html_entities_in_json=,
99
:encode_big_decimal_as_string, :encode_big_decimal_as_string=,
1010
:json_encoder, :json_encoder=,
@@ -106,9 +106,9 @@ class << self
106106
# as a safety measure.
107107
attr_accessor :escape_html_entities_in_json
108108

109-
# Configures the inclusion of subsecond resolution when serializing instances
110-
# of ActiveSupport::TimeWithZone.
111-
attr_accessor :subsecond_fraction_digits
109+
# Sets the precision of encoded time values.
110+
# Defaults to 3 (equivalent to millisecond precision)
111+
attr_accessor :time_precision
112112

113113
# Sets the encoder used by Rails to encode Ruby objects into JSON strings
114114
# in +Object#to_json+ and +ActiveSupport::JSON.encode+.

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 05:15:10 -1000"
155155
def as_json(options = nil)
156156
if ActiveSupport::JSON::Encoding.use_standard_json_time_format
157-
digits = ActiveSupport::JSON::Encoding.subsecond_fraction_digits || 3
157+
digits = ActiveSupport::JSON::Encoding.time_precision || 3
158158
xmlschema(digits)
159159
else
160160
%(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)})

activesupport/test/json/encoding_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,15 +466,15 @@ def test_twz_to_json_with_use_standard_json_time_format_config_set_to_true
466466
end
467467
end
468468

469-
def test_twz_to_json_with_custom_subsecond_resolution
469+
def test_twz_to_json_with_custom_time_precision
470470
with_standard_json_time_format(true) do
471-
ActiveSupport::JSON::Encoding.subsecond_fraction_digits = 0
471+
ActiveSupport::JSON::Encoding.time_precision = 0
472472
zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
473473
time = ActiveSupport::TimeWithZone.new(Time.utc(2000), zone)
474474
assert_equal "\"1999-12-31T19:00:00-05:00\"", ActiveSupport::JSON.encode(time)
475475
end
476476
ensure
477-
ActiveSupport::JSON::Encoding.subsecond_fraction_digits = nil
477+
ActiveSupport::JSON::Encoding.time_precision = nil
478478
end
479479

480480
def test_twz_to_json_when_wrapping_a_date_time

guides/source/configuring.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ There are a few configuration options available in Active Support:
441441
442442
* `config.active_support.use_standard_json_time_format` enables or disables serializing dates to ISO 8601 format. Defaults to `true`.
443443
444+
* `config.active_support.time_precision` sets the precision of JSON encoded time values. Defaults to `3`.
445+
444446
* `ActiveSupport::Logger.silencer` is set to `false` to disable the ability to silence logging in a block. The default is `true`.
445447
446448
* `ActiveSupport::Cache::Store.logger` specifies the logger to use within cache store operations.

0 commit comments

Comments
 (0)