Am I going insane? time attributes lose their value and reset to January 1 2000 after saving the active record object. The db is Postgres. Rails 5.2 and pg gem 1.1.3
2.6.6 :019 > obj.end_time = Date.new(2019, 9,9)
=> Mon, 09 Sep 2019
2.6.6 :020 > obj.save
=> true
2.6.6 :021 > obj.end_time
=> Mon, 09 Sep 2019 00:00:00 UTC +00:00
2.6.6 :022 > obj.end_time.class
=> ActiveSupport::TimeWithZone
But now if I reload from the db, the value is reset:
2.6.6 :023 > obj.reload
2.6.6 :024 > obj.end_time
=> Sat, 01 Jan 2000 00:00:00 UTC +00:00
2.6.6 :025 > obj.end_time.class
=> ActiveSupport::TimeWithZone
The postgres column type is shown in psql as "time without time zone". I guess I just need to specify datetime instead of time in migrations if I want to set the date part?
I tried to change column type in a migration change_column :school_courses, :start_time, :datetime but got:
PG::DatatypeMismatch: ERROR: column "start_time" cannot be cast automatically to type timestamp without time zone HINT: You might need to specify "USING start_time::timestamp without time zone"
Not sure how to do this