Fix an edge case with dates during the Italian calendar reform! Hehe. Closes #7724.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6341 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2007-03-06 00:49:11 +00:00
parent e52c28a425
commit d1b08f4a75
3 changed files with 17 additions and 4 deletions

@ -2,7 +2,8 @@
* Fix has_many :through << with custom foreign keys. #6466, #7153 [naffis, Rich Collins] * Fix has_many :through << with custom foreign keys. #6466, #7153 [naffis, Rich Collins]
* Test DateTime native type in migrations. #7649 [fedot] * Test DateTime native type in migrations, including an edge case with dates
during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
* SQLServer: correctly schema-dump tables with no indexes or descending indexes. #7333, #7703 [Jakob S, Tom Ward] * SQLServer: correctly schema-dump tables with no indexes or descending indexes. #7333, #7703 [Jakob S, Tom Ward]

@ -115,7 +115,12 @@ def self.string_to_time(string)
time_hash[:sec_fraction] = microseconds(time_hash) time_hash[:sec_fraction] = microseconds(time_hash)
time_array = time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction) time_array = time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction)
# treat 0000-00-00 00:00:00 as nil # treat 0000-00-00 00:00:00 as nil
Time.send(Base.default_timezone, *time_array) rescue DateTime.new(*time_array[0..5]) rescue nil begin
Time.send(Base.default_timezone, *time_array)
rescue
# Append zero offset to account for dates skipped by calendar reform.
DateTime.new(*time_array[0..5] << 0 << 0) rescue nil
end
end end
def self.string_to_dummy_time(string) def self.string_to_dummy_time(string)

@ -263,9 +263,16 @@ def test_native_types
Person.connection.add_column "people", "favorite_day", :date Person.connection.add_column "people", "favorite_day", :date
Person.connection.add_column "people", "moment_of_truth", :datetime Person.connection.add_column "people", "moment_of_truth", :datetime
Person.connection.add_column "people", "male", :boolean Person.connection.add_column "people", "male", :boolean
assert_nothing_raised { Person.create :first_name => 'bob', :last_name => 'bobsen', :bio => "I was born ....", :age => 18, :height => 1.78, :wealth => BigDecimal.new("12345678901234567890.0123456789"), :birthday => 18.years.ago, :favorite_day => 10.days.ago, :moment_of_truth => "1817-10-25 21:40:18", :male => true }
bob = Person.find(:first)
assert_nothing_raised do
Person.create :first_name => 'bob', :last_name => 'bobsen',
:bio => "I was born ....", :age => 18, :height => 1.78,
:wealth => BigDecimal.new("12345678901234567890.0123456789"),
:birthday => 18.years.ago, :favorite_day => 10.days.ago,
:moment_of_truth => "1582-10-10 21:40:18", :male => true
end
bob = Person.find(:first)
assert_equal 'bob', bob.first_name assert_equal 'bob', bob.first_name
assert_equal 'bobsen', bob.last_name assert_equal 'bobsen', bob.last_name
assert_equal "I was born ....", bob.bio assert_equal "I was born ....", bob.bio