diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-02-20 23:38:06 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-02-23 11:15:00 +0900 |
commit | cfbde022eedde2ae45e2dde9e3d8792933f070f4 (patch) | |
tree | 98842ff6bc004631717fbb4aedf909169b44b9f4 /activerecord/test | |
parent | 5d78256ee31edddf9e5deb9a50f2633482279bc3 (diff) | |
download | rails-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/test')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/date_test.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/date_test.rb b/activerecord/test/cases/adapters/postgresql/date_test.rb index 1562acdcc3..a86abac2be 100644 --- a/activerecord/test/cases/adapters/postgresql/date_test.rb +++ b/activerecord/test/cases/adapters/postgresql/date_test.rb @@ -21,4 +21,22 @@ class PostgresqlDateTest < ActiveRecord::PostgreSQLTestCase topic = Topic.create!(last_read: -1.0 / 0.0) assert_equal(-1.0 / 0.0, topic.last_read) end + + def test_bc_date + date = Date.new(0) - 1.week + topic = Topic.create!(last_read: date) + assert_equal date, Topic.find(topic.id).last_read + end + + def test_bc_date_leap_year + date = Time.utc(-4, 2, 29).to_date + topic = Topic.create!(last_read: date) + assert_equal date, Topic.find(topic.id).last_read + end + + def test_bc_date_year_zero + date = Time.utc(0, 4, 7).to_date + topic = Topic.create!(last_read: date) + assert_equal date, Topic.find(topic.id).last_read + end end |