File tree Expand file tree Collapse file tree 4 files changed +10
-8
lines changed Expand file tree Collapse file tree 4 files changed +10
-8
lines changed Original file line number Diff line number Diff line change 4
4
module ActiveSupport
5
5
class << self
6
6
delegate :use_standard_json_time_format , :use_standard_json_time_format= ,
7
- :subsecond_fraction_digits , :subsecond_fraction_digits = ,
7
+ :time_precision , :time_precision = ,
8
8
:escape_html_entities_in_json , :escape_html_entities_in_json= ,
9
9
:encode_big_decimal_as_string , :encode_big_decimal_as_string= ,
10
10
:json_encoder , :json_encoder= ,
@@ -106,9 +106,9 @@ class << self
106
106
# as a safety measure.
107
107
attr_accessor :escape_html_entities_in_json
108
108
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
112
112
113
113
# Sets the encoder used by Rails to encode Ruby objects into JSON strings
114
114
# in +Object#to_json+ and +ActiveSupport::JSON.encode+.
Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ def xmlschema(fraction_digits = 0)
154
154
# # => "2005/02/01 05:15:10 -1000"
155
155
def as_json ( options = nil )
156
156
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
158
158
xmlschema ( digits )
159
159
else
160
160
%(#{ time . strftime ( "%Y/%m/%d %H:%M:%S" ) } #{ formatted_offset ( false ) } )
Original file line number Diff line number Diff line change @@ -466,15 +466,15 @@ def test_twz_to_json_with_use_standard_json_time_format_config_set_to_true
466
466
end
467
467
end
468
468
469
- def test_twz_to_json_with_custom_subsecond_resolution
469
+ def test_twz_to_json_with_custom_time_precision
470
470
with_standard_json_time_format ( true ) do
471
- ActiveSupport ::JSON ::Encoding . subsecond_fraction_digits = 0
471
+ ActiveSupport ::JSON ::Encoding . time_precision = 0
472
472
zone = ActiveSupport ::TimeZone [ 'Eastern Time (US & Canada)' ]
473
473
time = ActiveSupport ::TimeWithZone . new ( Time . utc ( 2000 ) , zone )
474
474
assert_equal "\" 1999-12-31T19:00:00-05:00\" " , ActiveSupport ::JSON . encode ( time )
475
475
end
476
476
ensure
477
- ActiveSupport ::JSON ::Encoding . subsecond_fraction_digits = nil
477
+ ActiveSupport ::JSON ::Encoding . time_precision = nil
478
478
end
479
479
480
480
def test_twz_to_json_when_wrapping_a_date_time
Original file line number Diff line number Diff line change @@ -441,6 +441,8 @@ There are a few configuration options available in Active Support:
441
441
442
442
* `config.active_support.use_standard_json_time_format` enables or disables serializing dates to ISO 8601 format. Defaults to `true`.
443
443
444
+ * `config.active_support.time_precision` sets the precision of JSON encoded time values. Defaults to `3`.
445
+
444
446
* `ActiveSupport::Logger.silencer` is set to `false` to disable the ability to silence logging in a block. The default is `true`.
445
447
446
448
* `ActiveSupport::Cache::Store.logger` specifies the logger to use within cache store operations.
You can’t perform that action at this time.
0 commit comments