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

Changeset 8199

Show
Ignore:
Timestamp:
11/24/07 04:59:21 (1 year ago)
Author:
gbuesing
Message:

Honor Ruby's default calendar reform setting when creating DateTime objects via ActiveRecord's Time -> DateTime overflow, Time#time_with_datetime_fallback, Time#to_datetime, Date#to_datetime and String#to_datetime. Closes #10201

Files:

Legend:

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

    r8178 r8199  
    11*SVN* 
     2 
     3* DateTimes use Ruby's default calendar reform setting. #10201 [Geoff Buesing] 
    24 
    35* Dynamic finders on association collections respect association :order and :limit.  #10211, #10227 [Patrick Joyce, Rick Olson, Jack Danger Canty] 
  • trunk/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb

    r8113 r8199  
    175175          rescue ArgumentError, TypeError 
    176176            zone_offset = Base.default_timezone == :local ? DateTime.local_offset : 0 
    177             # Append zero calendar reform start to account for dates skipped by calendar reform 
    178             DateTime.new(year, mon, mday, hour, min, sec, zone_offset, 0) rescue nil 
     177            DateTime.civil(year, mon, mday, hour, min, sec, zone_offset) rescue nil 
    179178          end 
    180179 
  • trunk/activerecord/test/migration_test.rb

    r7996 r8199  
    287287          :wealth => BigDecimal.new("12345678901234567890.0123456789"), 
    288288          :birthday => 18.years.ago, :favorite_day => 10.days.ago, 
    289           :moment_of_truth => "1582-10-10 21:40:18", :male => true 
     289          :moment_of_truth => "1782-10-10 21:40:18", :male => true 
    290290      end 
    291291 
     
    324324        assert_not_equal 0, bob.moment_of_truth.offset 
    325325        assert_not_equal "Z", bob.moment_of_truth.zone 
     326        assert_equal DateTime::ITALY, bob.moment_of_truth.start 
    326327      end 
    327328 
  • trunk/activesupport/CHANGELOG

    r8198 r8199  
    11*SVN* 
     2 
     3* Time#time_with_datetime_fallback, Time#to_datetime, Date#to_datetime and String#to_datetime honor Ruby's default calendar reform setting. #10201 [Geoff Buesing] 
    24 
    35* Change Time and DateTime #end_of_month to return last second of month instead of beginning of last day of month. Closes #10200 [Geoff Buesing] 
  • trunk/activesupport/lib/active_support/core_ext/date/conversions.rb

    r7647 r8199  
    5454        # Converts self to a Ruby DateTime object; time is set to beginning of day 
    5555        def to_datetime 
    56           ::DateTime.civil(year, month, day, 0, 0, 0, 0, 0
     56          ::DateTime.civil(year, month, day, 0, 0, 0, 0
    5757        end if RUBY_VERSION < '1.9' 
    5858 
  • trunk/activesupport/lib/active_support/core_ext/string/conversions.rb

    r6935 r8199  
    1616         
    1717        def to_datetime 
    18           ::DateTime.civil(*ParseDate.parsedate(self)[0..5].map {|arg| arg || 0} << 0 << 0
     18          ::DateTime.civil(*ParseDate.parsedate(self)[0..5].map {|arg| arg || 0} << 0
    1919        end 
    2020      end 
  • trunk/activesupport/lib/active_support/core_ext/time/calculations.rb

    r8198 r8199  
    3737          rescue 
    3838            offset = utc_or_local.to_sym == :local ? ::DateTime.local_offset : 0 
    39             ::DateTime.civil(year, month, day, hour, min, sec, offset, 0
     39            ::DateTime.civil(year, month, day, hour, min, sec, offset
    4040          end 
    4141 
  • trunk/activesupport/lib/active_support/core_ext/time/conversions.rb

    r7647 r8199  
    4444        # converts to a Ruby DateTime instance; preserves utc offset 
    4545        def to_datetime 
    46           ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400), 0
     46          ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400)
    4747        end 
    4848      end 
  • trunk/activesupport/test/core_ext/date_ext_test.rb

    r8076 r8199  
    2424  def test_to_datetime 
    2525    assert_equal DateTime.civil(2005, 2, 21), Date.new(2005, 2, 21).to_datetime 
     26    assert_equal 0, Date.new(2005, 2, 21).to_datetime.offset # use UTC offset 
     27    assert_equal ::Date::ITALY, Date.new(2005, 2, 21).to_datetime.start # use Ruby's default start value 
    2628  end 
    2729 
  • trunk/activesupport/test/core_ext/string_ext_test.rb

    r7656 r8199  
    8484    assert_equal DateTime.civil(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time 
    8585    assert_equal Time.local_time(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_time(:local) 
     86  end 
     87   
     88  def test_string_to_datetime 
     89    assert_equal DateTime.civil(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_datetime 
     90    assert_equal 0, "2039-02-27 23:50".to_datetime.offset # use UTC offset 
     91    assert_equal ::Date::ITALY, "2039-02-27 23:50".to_datetime.start # use Ruby's default start value 
     92  end 
     93   
     94  def test_string_to_date 
    8695    assert_equal Date.new(2005, 2, 27), "2005-02-27".to_date 
    87     assert_equal DateTime.civil(2039, 2, 27, 23, 50), "2039-02-27 23:50".to_datetime 
    8896  end 
    8997 
  • trunk/activesupport/test/core_ext/time_ext_test.rb

    r8198 r8199  
    335335      assert_equal Time.local(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, Rational(Time.local(2005, 2, 21, 17, 44, 30).utc_offset, 86400), 0) 
    336336    end 
     337    assert_equal ::Date::ITALY, Time.utc(2005, 2, 21, 17, 44, 30).to_datetime.start # use Ruby's default start value 
    337338  end 
    338339 
     
    379380    assert_equal Time.time_with_datetime_fallback(:utc, 2005, 2, 21, 17, 44, 30, 1), Time.utc(2005, 2, 21, 17, 44, 30, 1) #with usec 
    380381    assert_equal Time.time_with_datetime_fallback(:utc, 2039, 2, 21, 17, 44, 30, 1), DateTime.civil(2039, 2, 21, 17, 44, 30, 0, 0) 
     382    assert_equal ::Date::ITALY, Time.time_with_datetime_fallback(:utc, 2039, 2, 21, 17, 44, 30, 1).start # use Ruby's default start value 
    381383  end 
    382384