Time zones and testing in rails

Fishy things happen when testing time-sensitive SQL queries that my model layer executes. (For instance, queries that return records with a date earlier than the current date).

The application is set to China Standard Time, and I am located in the US when running the tests. Here is some console output that I think points to the underlying problem. I’ve not yet found the solution

# in config/application.rb
config.time_zone = "Asia/Shanghai"

# in rails console
Loading development environment (Rails 4.0.2)
2.0.0p247 :001 > Date.today
 => Sun, 29 Dec 2013 
2.0.0p247 :002 > Date.yesterday
 => Sun, 29 Dec 2013 
2.0.0p247 :003 > Date.tomorrow
 => Tue, 31 Dec 2013 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s