aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-21 09:34:55 -0800
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-21 09:34:55 -0800
commit1c0e7ab2f8227598cd605e3cee74e16d66c17c43 (patch)
treedcb7edce622bb316309288f8893983fa107dfd52 /activerecord/lib/active_record/connection_adapters
parent6b266c21b2cc649505e5f31c74e1f450f3287981 (diff)
parentfa73cf727521e9eb7911ada4d30ac10406446e7d (diff)
downloadrails-1c0e7ab2f8227598cd605e3cee74e16d66c17c43.tar.gz
rails-1c0e7ab2f8227598cd605e3cee74e16d66c17c43.tar.bz2
rails-1c0e7ab2f8227598cd605e3cee74e16d66c17c43.zip
Merge pull request #6245 from bogdan/bc_timestamp
Postgresql adapter: fix handling of BC timestamps
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/cast.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb10
2 files changed, 9 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb
index 62d091357d..c04a799b8d 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb
@@ -8,6 +8,8 @@ module ActiveRecord
case string
when 'infinity'; 1.0 / 0.0
when '-infinity'; -1.0 / 0.0
+ when / BC$/
+ super("-" + string.sub(/ BC$/, ""))
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 9d3fa18e3a..62a4d76928 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
@@ -129,11 +129,15 @@ module ActiveRecord
# 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