Nona
Nona

Reputation: 5462

Will a rake task respect the time zone of a date object argument?

So if I have a Rails 4 application on Heroku with config/application.rb set to Pacific time,

config.time_zone = 'Pacific Time (US & Canada)'

if I passed in a Time argument to a rake task, say Time.new(2016, 15, 3, 11, 59, 59, "-08:00") to do a date comparison of the argument against an object's created_at field, then this would be the correct relative comparison? (In other words, I shouldn't adjust the UTC time by "+02:00")

Or can I pass in Time.new(2016, 15, 3) and Ruby / Rails would automatically assume the Time object is in Pacific time without me having to add the "-08:00"?

Upvotes: 0

Views: 435

Answers (1)

archana
archana

Reputation: 1272

First, correct time object: Time.new(2016, 3, 15) # year, month, date

"Or can I pass in Time.new(2016, 15, 3) and Ruby / Rails would automatically assume the Time object is in Pacific time without me having to add the "-08:00"?"

Answer is yes. Rails will interpret it as "2016-03-15 00:00:00 -0700".

Upvotes: 1

Related Questions