提交 f4bd67b6 编写于 作者: E edogawaconan

Fix behavior of handling BC era dates.

BC era year is (astronomical year + 1) and starts from 1 BC.
上级 bb8b2141
......@@ -11,7 +11,8 @@ def cast_value(value)
when 'infinity' then ::Float::INFINITY
when '-infinity' then -::Float::INFINITY
when / BC$/
super("-" + value.sub(/ BC$/, ""))
astronomical_year = format("%04d", -value[/^\d+/].to_i + 1)
super(value.sub(/ BC$/, "").sub(/^\d+/, astronomical_year))
else
super
end
......
......@@ -149,8 +149,9 @@ def quoted_date(value) #:nodoc:
result = "#{result}.#{sprintf("%06d", value.usec)}"
end
if value.year < 0
result = result.sub(/^-/, "") + " BC"
if value.year <= 0
bce_year = format("%04d", -value.year + 1)
result = result.sub(/^-?\d+/, bce_year) + " BC"
end
result
end
......
......@@ -123,6 +123,18 @@ def test_bc_timestamp
assert_equal date, Developer.find_by_name("aaron").updated_at
end
def test_bc_timestamp_leap_year
date = Time.utc(-4, 2, 29)
Developer.create!(:name => "taihou", :updated_at => date)
assert_equal date, Developer.find_by_name("taihou").updated_at
end
def test_bc_timestamp_year_zero
date = Time.utc(0, 4, 7)
Developer.create!(:name => "yahagi", :updated_at => date)
assert_equal date, Developer.find_by_name("yahagi").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.
先完成此消息的编辑!
想要评论请 注册