diff options
author | Matthew Draper <matthew@trebex.net> | 2014-06-05 23:35:14 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2014-06-05 23:35:14 +0930 |
commit | e496a25251dc9c1b455bf9e97baaf58b0e99840b (patch) | |
tree | 9000a5c916361a7345b75b558f1f052eb1924b2a /activerecord/lib | |
parent | 1c39310637599df879c0412672f35d3990b61afb (diff) | |
parent | f4bd67b687ba1a2a6f907939ea44717b41a505e1 (diff) | |
download | rails-e496a25251dc9c1b455bf9e97baaf58b0e99840b.tar.gz rails-e496a25251dc9c1b455bf9e97baaf58b0e99840b.tar.bz2 rails-e496a25251dc9c1b455bf9e97baaf58b0e99840b.zip |
Merge pull request #15521 from edogawaconan/fix_bc_postgres_master
Fix BC year handling in postgres
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid/date_time.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb | 5 |
2 files changed, 5 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/date_time.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/date_time.rb index 9ccbf71159..34e2276dd1 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/date_time.rb @@ -11,7 +11,8 @@ module ActiveRecord 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 diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb index 4c719b834f..3cf40e6cd4 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb @@ -149,8 +149,9 @@ module ActiveRecord 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 |