You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you're coding any functionality that has a dependency on time of day, do not useTime.now to mean the current time!
The reason is that Time.now returns the current time in the timezone where this computer (the one running the test) is located, but what you want is the time in the application's time zone.
We are making the application's time zone UTC (basically, GMT) since we will have users in all different time zones and each user can set the TZ in which they view and enter times. All times will be stored as UTC, and all time-dependent tasks will reckon time in UTC.
Therefore please use Time.zone.now to get the current time. Here is a good article on this gotcha. I've modified the Gemfile to include the timecop gem, which you can use to stub the clock in your tests.
The text was updated successfully, but these errors were encountered:
If you're coding any functionality that has a dependency on time of day, do not use
Time.now
to mean the current time!The reason is that
Time.now
returns the current time in the timezone where this computer (the one running the test) is located, but what you want is the time in the application's time zone.We are making the application's time zone UTC (basically, GMT) since we will have users in all different time zones and each user can set the TZ in which they view and enter times. All times will be stored as UTC, and all time-dependent tasks will reckon time in UTC.
Therefore please use
Time.zone.now
to get the current time. Here is a good article on this gotcha. I've modified the Gemfile to include thetimecop
gem, which you can use to stub the clock in your tests.The text was updated successfully, but these errors were encountered: