From f4bd67b687ba1a2a6f907939ea44717b41a505e1 Mon Sep 17 00:00:00 2001 From: edogawaconan Date: Thu, 5 Jun 2014 18:31:39 +0900 Subject: Fix behavior of handling BC era dates. BC era year is (astronomical year + 1) and starts from 1 BC. --- .../active_record/connection_adapters/postgresql/oid/date_time.rb | 3 ++- .../lib/active_record/connection_adapters/postgresql/quoting.rb | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'activerecord/lib') 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 -- cgit v1.2.3