aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-02-20 23:38:06 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-02-23 11:15:00 +0900
commitcfbde022eedde2ae45e2dde9e3d8792933f070f4 (patch)
tree98842ff6bc004631717fbb4aedf909169b44b9f4 /activerecord/lib/active_record
parent5d78256ee31edddf9e5deb9a50f2633482279bc3 (diff)
downloadrails-cfbde022eedde2ae45e2dde9e3d8792933f070f4.tar.gz
rails-cfbde022eedde2ae45e2dde9e3d8792933f070f4.tar.bz2
rails-cfbde022eedde2ae45e2dde9e3d8792933f070f4.zip
PostgreSQL: Allow BC dates like datetime consistently
BC dates are supported by both date and datetime types. https://www.postgresql.org/docs/current/static/datatype-datetime.html Since #1097, new datetime allows year zero as 1 BC, but new date does not. It should be allowed even in new date consistently.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/date.rb3
1 files changed, 3 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/date.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/date.rb
index 4f010e0bf8..24a1daa95a 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/date.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/date.rb
@@ -9,6 +9,9 @@ module ActiveRecord
case value
when "infinity" then ::Float::INFINITY
when "-infinity" then -::Float::INFINITY
+ when / BC$/
+ astronomical_year = format("%04d", -value[/^\d+/].to_i + 1)
+ super(value.sub(/ BC$/, "").sub(/^\d+/, astronomical_year))
else
super
end