Read more

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

Martin Straub
July 25, 2012Software engineer at makandra GmbH

... you probably have a time zone issue.

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

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.

Posted by Martin Straub to makandra dev (2012-07-25 11:20)