Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 7746

Show
Ignore:
Timestamp:
10/05/07 09:43:24 (9 months ago)
Author:
bitsweat
Message:

Disambiguate Time, Date, and DateTime#to_json formatting. Closes #9750.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r7739 r7746  
    11*SVN* 
     2 
     3* Disambiguate Time, Date, and DateTime#to_json formatting.  #9750 [Geoff Buesing, Chu Yeow] 
    24 
    35* Hash#to_json takes :only or :except options to specific or omit certain hash keys. Enumerable#to_json passes through its options to each element.  #9751 [Chu Yeow] 
  • trunk/activesupport/lib/active_support/json/encoders/date_time.rb

    r7736 r7746  
    11class DateTime 
    22  def to_json(options = nil) #:nodoc: 
    3     %("#{strftime("%m/%d/%Y %H:%M:%S %Z")}") 
     3    %("#{strftime("%Y/%m/%d %H:%M:%S %z")}") 
    44  end 
    55end 
  • trunk/activesupport/lib/active_support/json/encoders/date.rb

    r7736 r7746  
    11class Date 
    22  def to_json(options = nil) #:nodoc: 
    3     %("#{strftime("%m/%d/%Y")}") 
     3    %("#{strftime("%Y/%m/%d")}") 
    44  end 
    55end 
  • trunk/activesupport/lib/active_support/json/encoders/time.rb

    r7736 r7746  
    11class Time 
    22  def to_json(options = nil) #:nodoc: 
    3     %("#{strftime("%m/%d/%Y %H:%M:%S %Z")}"
     3    to_datetime.to_json(options
    44  end 
    55end 
  • trunk/activesupport/test/json/encoding_test.rb

    r7736 r7746  
    3030  RegexpTests   = [[ /^a/, '/^a/' ], [/^\w{1,2}[a-z]+/ix, '/^\\w{1,2}[a-z]+/ix']] 
    3131 
    32   DateTests     = [[ Date.new(2005,1,1), %("01/01/2005") ]] 
    33   TimeTests     = [[ Time.at(0), %("#{Time.at(0).strftime('%m/%d/%Y %H:%M:%S %Z')}") ]] 
    34   DateTimeTests = [[ DateTime.new(0), %("#{DateTime.new(0).strftime('%m/%d/%Y %H:%M:%S %Z')}") ]] 
     32  DateTests     = [[ Date.new(2005,2,1), %("2005/02/01") ]] 
     33  TimeTests     = [[ Time.utc(2005,2,1,15,15,10), %("2005/02/01 15:15:10 +0000") ]] 
     34  DateTimeTests = [[ DateTime.civil(2005,2,1,15,15,10), %("2005/02/01 15:15:10 +0000") ]] 
    3535 
    3636  constants.grep(/Tests$/).each do |class_tests|