Normally, Rails stores all times in the database in UTC time. If you set your time zone to be something else, it converts automatically between that zone and UTC when you save to the database or retrieve from it.
What are some of the advantages of this approach? Are there any disadvantages? Is there any way to have Rails use a different time zone?
I think some of the advantages may be:
- UTC removes the ambiguities of seasonal time changes
- You can present different time zones to different users while keeping things consistent in the database
The only disadvantage I can think of is that, for an internal app where all users are actually in the same time zone, this difference makes it harder to run raw SQL queries based on local time.
This question has a little bit of a religious feel to it, but I’m going to answer it based on my personal experience.
Always store dates in an unambiguous form. Storing the date in UTC is pretty much the standard in that regard.
Advantages:
Disadvantages:
Can you get rails to do something different? Possibly, but I’ve never tried as it just was too much work to fight what IMHO was a sensible design.
Does it make sense to use UTC from a ‘just use my timezone’ sense? Yes. Your server could be in California, your users in New York and who decides what is local time in that case. The server? The users? Mike, who just happens to be in London for the week on a business trip? In this case what timezone do you use?