Changeset 9203
- Timestamp:
- 04/01/08 20:25:26 (3 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/json.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/json/encoders/date_time.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/json/encoders/date.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/json/encoders/time.rb (modified) (1 diff)
- trunk/activesupport/test/json/encoding_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r9153 r9203 1 1 *SVN* 2 3 * Add config.active_support.use_standard_json_time_format setting so that Times and Dates export to ISO 8601 dates. [rick] 2 4 3 5 * TZInfo: Removing unneeded TimezoneProxy class [Geoff Buesing] trunk/activesupport/lib/active_support/json.rb
r6443 r9203 3 3 4 4 module ActiveSupport 5 mattr_accessor :use_standard_json_time_format 6 5 7 module JSON 6 8 RESERVED_WORDS = %w( trunk/activesupport/lib/active_support/json/encoders/date_time.rb
r9093 r9203 6 6 # # => "2005/02/01 15:15:10 +0000" 7 7 def to_json(options = nil) 8 %("#{strftime("%Y/%m/%d %H:%M:%S %z")}") 8 if ActiveSupport.use_standard_json_time_format 9 xmlschema.inspect 10 else 11 %("#{strftime("%Y/%m/%d %H:%M:%S %z")}") 12 end 9 13 end 10 14 end trunk/activesupport/lib/active_support/json/encoders/date.rb
r9093 r9203 6 6 # # => "2005/02/01" 7 7 def to_json(options = nil) 8 %("#{strftime("%Y/%m/%d")}") 8 if ActiveSupport.use_standard_json_time_format 9 %("#{strftime("%Y-%m-%d")}") 10 else 11 %("#{strftime("%Y/%m/%d")}") 12 end 9 13 end 10 14 end trunk/activesupport/lib/active_support/json/encoders/time.rb
r9093 r9203 6 6 # # => 2005/02/01 15:15:10 +0000" 7 7 def to_json(options = nil) 8 %("#{strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}") 8 if ActiveSupport.use_standard_json_time_format 9 utc.xmlschema.inspect 10 else 11 %("#{strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}") 12 end 9 13 end 10 14 end trunk/activesupport/test/json/encoding_test.rb
r8789 r9203 36 36 DateTimeTests = [[ DateTime.civil(2005,2,1,15,15,10), %("2005/02/01 15:15:10 +0000") ]] 37 37 38 StandardDateTests = [[ Date.new(2005,2,1), %("2005-02-01") ]] 39 StandardTimeTests = [[ Time.utc(2005,2,1,15,15,10), %("2005-02-01T15:15:10Z") ]] 40 StandardDateTimeTests = [[ DateTime.civil(2005,2,1,15,15,10), %("2005-02-01T15:15:10+00:00") ]] 41 38 42 constants.grep(/Tests$/).each do |class_tests| 39 define_method("test_#{class_tests[0..-6].downcase}") do 40 self.class.const_get(class_tests).each do |pair| 41 assert_equal pair.last, pair.first.to_json 43 define_method("test_#{class_tests[0..-6].underscore}") do 44 begin 45 ActiveSupport.use_standard_json_time_format = class_tests =~ /^Standard/ 46 self.class.const_get(class_tests).each do |pair| 47 assert_equal pair.last, pair.first.to_json 48 end 49 ensure 50 ActiveSupport.use_standard_json_time_format = false 42 51 end 43 52 end