diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2015-02-01 13:02:56 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2015-02-08 22:22:55 +0900 |
commit | f9839120379292cbc5da25f35311f457b08b44a8 (patch) | |
tree | 32d780f568088bbfa3519a0f8ca23137ca7d533a /activerecord/lib/active_record/connection_adapters/postgresql/oid/date_time.rb | |
parent | 31fafe0a3223b58e214c03c88a33d6ef4435f63c (diff) | |
download | rails-f9839120379292cbc5da25f35311f457b08b44a8.tar.gz rails-f9839120379292cbc5da25f35311f457b08b44a8.tar.bz2 rails-f9839120379292cbc5da25f35311f457b08b44a8.zip |
Fix rounding problem for PostgreSQL timestamp column
If timestamp column have the precision, it need to format according to
the precision of timestamp column.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/oid/date_time.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/oid/date_time.rb | 9 |
1 files changed, 9 insertions, 0 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 b9e7894e5c..2fe61eeb77 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 @@ -5,6 +5,15 @@ module ActiveRecord class DateTime < Type::DateTime # :nodoc: include Infinity + def type_cast_for_database(value) + if has_precision? && value.acts_like?(:time) && value.year <= 0 + bce_year = format("%04d", -value.year + 1) + super.sub(/^-?\d+/, bce_year) + " BC" + else + super + end + end + def cast_value(value) if value.is_a?(::String) case value |