Read more

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

Deleted user #6
July 25, 2012Software engineer

... you probably have a time zone issue.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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 to makandra dev (2012-07-25 11:20)