Time zone bug for :datetime attributes?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Time zone bug for :datetime attributes?

Andrew Kaspick
I've noticed a time zone bug in the following code...


That's creating a new time with either :utc or :local.  The issue is when using :local, that creates a new time based on the systems local time zone, and ignores the time set in the app via config.time_zone = 'Central Time (US & Canada)'

So if the app is set for CST (via config.time_zone), but the local system time zone in EST, the time will be created for EST even if the app is set for CST.

So in code such as
class FormObject
  include ActiveModel::Model
  include ActiveModel::Attributes
  include ActiveRecord::AttributeAssignment
  attribute :received_at, :datetime
end

obj = FormObject.new received_at: '2020-01-02 00:50'
obj.received_at # 2020-01-02 00:50:00 -0500 => should be 2020-01-02 00:50:00 -0600

The resulting time is wrong because the time zone set in the app is being ignored.

Any reason this would be occurring the way it is or is it a bug?

Regards,
Andrew

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/CAEUKiYFTjFQSXGz3XbSc%2B31HfTw%2BBWJt%3DpHGNHvmqJ7RDmg6Ew%40mail.gmail.com.