5

I'm seeing something very odd.

<h3><%= (Date.today).strftime("%A, %B %d, %Y")  %></h3>

is resulting in Wednesday, October 09, 2013 which is correct.

However, this results in Friday, October 11, 2013.

<h3><%= (Date.tomorrow).strftime("%A, %B %d, %Y")  %></h3>

It completely skips Thursday (which is truly tomorrow).

Any ideas?

brad
  • 1,675
  • 2
  • 16
  • 23
  • I assume knowing the exact time (and timezone) when you tested this might be of use. – Amadan Oct 10 '13 at 01:00
  • Yes, however under no timezone circumstances should tomorrow be 2 days from today. – brad Oct 10 '13 at 01:03
  • I can think of at least one possibility, at the break of the [DST](http://en.wikipedia.org/wiki/Daylight_saving_time) . For me, this gives `Thursday` and `Friday` respectively, so I'd need the exact timestamp if I am to see the phenomenon. – Amadan Oct 10 '13 at 01:04
  • even in rails console date.today is the 9th and date.tomorrow is the 11th. not DST so do not think that is it. – brad Oct 10 '13 at 01:08

2 Answers2

5

The method tomorrow isn't in Ruby - only in Rails. Maybe your Ruby and your Rails are set for different timezones. What do you get from Date.current, which is basically today in rails?

BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
Steve Kass
  • 7,144
  • 20
  • 26
  • date.current i get tomorrow. that explains it i believe. what's the best way to get these in synch? basically, date.current should be central time in the US. thank you! – brad Oct 10 '13 at 01:10
  • I don't know what best practice is, but maybe you haven't defined a timezone (https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/date/calculations.rb). You might want to dig around for other threads on this topic, and for the time being, compute tomorrow by adding one day to today, instead of invoking two different methods. – Steve Kass Oct 10 '13 at 01:20
  • The fix to this for me was un-commenting out config.time_zone = 'Central Time (US & Canada)' in the application.rb time zone. You deal with timezones in this file. This post was also helpful for additional info: http://stackoverflow.com/questions/6118779/how-to-change-default-timezone-for-activerecord-in-rails3 – brad Oct 10 '13 at 01:34
2

Rails-Date has provided current method to compliment today method of Ruby-Date. So now you can use:

Date.current     # Rails equivalent of Ruby's - Date.today
Date.tomorrow

for all dates which should be respecting Rails timezone and Ruby-Date.today keeps being what it is.

Sachin
  • 963
  • 11
  • 31