aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json
diff options
context:
space:
mode:
authorParker Selbert <parker@sorentwo.com>2013-07-16 16:16:33 -0400
committerAndrew White <andyw@pixeltrix.co.uk>2014-01-26 21:25:54 +0000
commit4cfc467594da86090efa63f1852fb82df9458c2b (patch)
treedbc771cf9747b324fe5614b569ff687d745de810 /activesupport/lib/active_support/json
parente1e17a55d246d485f546766606580e8e4919442b (diff)
downloadrails-4cfc467594da86090efa63f1852fb82df9458c2b.tar.gz
rails-4cfc467594da86090efa63f1852fb82df9458c2b.tar.bz2
rails-4cfc467594da86090efa63f1852fb82df9458c2b.zip
Customize subsecond digits when encoding DateWithTime
The subsecond fraction digits had been hardcoded to 3. This forced all timestamps to include the subsecond digits with no way to customize the value. While the subsecond format is part of the ISO8601 spec, it is not adhered to by all parsers (notably mobile clients). This adds the ability to customize the number of digits used, optionally setting them to 0 in order to eliminate the subsecond fraction entirely: ActiveSupport::JSON::Encoding.subsecond_fraction_digits = 0
Diffstat (limited to 'activesupport/lib/active_support/json')
-rw-r--r--activesupport/lib/active_support/json/encoding.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index 2859075e10..23896316e2 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -4,6 +4,7 @@ require 'active_support/core_ext/module/delegation'
module ActiveSupport
class << self
delegate :use_standard_json_time_format, :use_standard_json_time_format=,
+ :subsecond_fraction_digits, :subsecond_fraction_digits=,
:escape_html_entities_in_json, :escape_html_entities_in_json=,
:encode_big_decimal_as_string, :encode_big_decimal_as_string=,
:json_encoder, :json_encoder=,
@@ -60,7 +61,7 @@ module ActiveSupport
end
# Mark these as private so we don't leak encoding-specific constructs
- private_constant :ESCAPED_CHARS, :ESCAPE_REGEX_WITH_HTML_ENTITIES,
+ private_constant :ESCAPED_CHARS, :ESCAPE_REGEX_WITH_HTML_ENTITIES,
:ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, :EscapedString
# Convert an object into a "JSON-ready" representation composed of
@@ -105,6 +106,10 @@ module ActiveSupport
# as a safety measure.
attr_accessor :escape_html_entities_in_json
+ # Configures the inclusion of subsecond resolution when serializing instances
+ # of ActiveSupport::TimeWithZone.
+ attr_accessor :subsecond_fraction_digits
+
# Sets the encoder used by Rails to encode Ruby objects into JSON strings
# in +Object#to_json+ and +ActiveSupport::JSON.encode+.
attr_accessor :json_encoder