I know there are a few dozen similar questions out there, not to mention countless articles on the Interwebs in general, but I'm still having a hard time understanding how Rails works with Time Zones internally.
I currently have config.time_zone = 'Eastern Time (US & Canada)'
configured in my application file because that's where I and the other project administrators are. The company that owns the site is based in CA, so they will be in Pacific time. The application has a global audience and while we haven't done so yet we will eventually be implementing user preferred time zones.
So my current questions:
I know Rails magically transforms datetime column values to and from UTC when stored and retrieved respectively, but what is the proper way to view the local version of a given datetime attribute?
When would one use
Time.now
versusTime.zone.now
versusTime.now.in_time_zone
versusDateTime.now
versusDateTime.now.in_time_zone
?What is the proper way to compare a given datetime attribute with the methods listed above or some other specific time relative to the currently configured time zone? With UTC?
We will have some time-sensitive things like articles that need to be published at a specific time according to the application's time zone, so how do I make the application do that comparison in our specified timezone as opposed to the currently configured one (assuming a user timezones are implemented?)
(New Question) What happens if I change
config.time_zone
toUTC
at a later date? Do I have to reset all of my times in the database or does it otherwise affect old times?
6. Is Rails sensitive to Daylight Savings Time and/or how do you implement time zone support that is sensitive?
and7. Is there a difference between how Rails handles time zones and DST for date columns vs. datetime columns?
and perhaps8. Is this database agnostic or does it need to be handled differently for SQLite vs. MySQL vs. others?
– Clay