1

I have a table with Time data type column, which stores times from users (via f.time_select form helper). It works fine when I input time through the form, but I can't create a time object from rails irb console with .create or .new. The message is:

irb(main):003:0> Sleep.create(hours: "1970-01-01 06:15:00") DEPRECATION WARNING: Time columns will become time zone aware in Rails 5.1. This still causes Strings to be parsed as if they were in Time.zone, and Times to be converted to Time.zone.

To keep the old behavior, you must add the following to your initializer:

config.active_record.time_zone_aware_types = [:datetime]

To silence this deprecation warning, add the following:

config.active_record.time_zone_aware_types = [:datetime, :time]  (called from irb_binding at (irb):3) DEPRECATION WARNING: Time columns

will become time zone aware in Rails 5.1. This still causes Strings to be parsed as if they were in Time.zone, and Times to be converted to Time.zone.

To keep the old behavior, you must add the following to your initializer:

config.active_record.time_zone_aware_types = [:datetime]

To silence this deprecation warning, add the following:

config.active_record.time_zone_aware_types = [:datetime, :time]

I was trying to add each of these lines to the config/application.rb under class Application < Rails::Application and then try different syntaxis combinations to create time through irb, like Sleep.create(hours: "1970-01-01", "06:20:00") but nothing worked.

I'm also getting results like this:

Loading development environment (Rails 5.0.2)
irb(main):001:0> irb(main):003:0> Sleep.create(hours: "1970-01-01 06:15:00")
SyntaxError: (irb):1: syntax error, unexpected ':', expecting end-of-input
irb(main):003:0> Sleep.create(hours: "19

or

Sleep.create(hours: "1970-01-01", "06:15:00")
irb(main):002:0> Sleep.create(hours: "1970-01-01", "06:15:00")
SyntaxError: (irb):2: syntax error, unexpected ')', expecting =>
urs: "1970-01-01", "06:15:00")

What am I doing wrong and how can I create some particular time from irb?

Evanto
  • 340
  • 4
  • 19
  • have a look at http://stackoverflow.com/questions/11444164/how-to-create-a-new-datetime-object-in-a-specific-time-zone-preferably-the-defa – Rakesh Apr 26 '17 at 19:58
  • Possible duplicate of [How to create a new DateTime object in a specific time zone (preferably the default time zone of my app, not UTC)?](http://stackoverflow.com/questions/11444164/how-to-create-a-new-datetime-object-in-a-specific-time-zone-preferably-the-defa) – Eyeslandic Apr 26 '17 at 20:35

0 Answers0