When Date.today and Date.tomorrow return the same day...

Posted Almost 12 years ago. Visible to the public.

... you probably have a time zone issue.

When you get

Timecop.travel(Date.parse("2011-11-11 00:00") do
  Time.current   => Thu, 10 Nov 2011 23:00:01 UTC +00:00
  Time.now       => Fri Nov 11 00:00:02 +0100 2011
  Date.today     => Fri, 11 Nov 2011
  Date.tomorrow  => Fri, 11 Nov 2011
end

you probably haven't defined a zime zone yet.

So might fix this by adding the following lines to your application.rb:

class Application < Rails::Application
  config.time_zone = 'Berlin' # or whatever your time zone
end

It seems Date.yesterday uses the time zone Time.current uses and Date.today uses the same time zone like Time.now.

Last edit
Almost 12 years ago
License
Source code in this card is licensed under the MIT License.
Posted to makandra dev (2012-07-25 09:20)