提交 fa73cf72 编写于 作者: B Bogdan Gusiev

Fix postgresql adapter to handle bc timestamps correctly

上级 f058e565
## Rails 4.0.0 (unreleased) ##
* Fix postgresql adapter to handle BC timestamps correctly
HistoryEvent.create!(:name => "something", :occured_at => Date.new(0) - 5.years)
*Bogdan Gusiev*
* When running migrations on Postgresql, the `:limit` option for `binary` and `text` columns is silently dropped.
Previously, these migrations caused sql exceptions, because Postgresql doesn't support limits on these types.
......
......@@ -8,6 +8,8 @@ def string_to_time(string)
case string
when 'infinity'; 1.0 / 0.0
when '-infinity'; -1.0 / 0.0
when / BC$/
super("-" + string.sub(/ BC$/, ""))
else
super
end
......
......@@ -129,11 +129,15 @@ def quote_column_name(name) #:nodoc:
# Quote date/time values for use in SQL input. Includes microseconds
# if the value is a Time responding to usec.
def quoted_date(value) #:nodoc:
result = super
if value.acts_like?(:time) && value.respond_to?(:usec)
"#{super}.#{sprintf("%06d", value.usec)}"
else
super
result = "#{result}.#{sprintf("%06d", value.usec)}"
end
if value.year < 0
result = result.sub(/^-/, "") + " BC"
end
result
end
end
end
......
......@@ -75,6 +75,15 @@ def test_postgres_agrees_with_activerecord_about_precision
assert_equal '4', pg_datetime_precision('foos', 'updated_at')
end
def test_bc_timestamp
unless current_adapter?(:PostgreSQLAdapter)
return skip("only tested on postgresql")
end
date = Date.new(0) - 1.second
Developer.create!(:name => "aaron", :updated_at => date)
assert_equal date, Developer.find_by_name("aaron").updated_at
end
private
def pg_datetime_precision(table_name, column_name)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册