I am having trouble understanding Rails' time zone support when it comes to daylight savings time.
I am storing all database times in UTC. User timezones are stored so that they map directly back to ActiveSupport::TimeZone
values (i.e. Central Time (US & Canada)
).
I want to completely ignore daylight savings time. If an event starts at 5:30pm
, it always starts at 5:30pm
whether daylight savings time is in effect or not.
Is it possible, considering all times are stored uniformly, to retrieve database times and display them locally so that daylight savings is completely ignored? Are there any problems I am going to run into ignoring daylight savings?
Rails is going to convert your dates/times to the application configured timezone or the user timezone (assuming you have setup some sort of filter to use the user.timezone); and this WILL include manipulation based on DST.
You will need to override this behavior and there are probably a couple of options:
I don't mean to sound pedantic, but...
Well, you will be on your own then. Despite our best hopes and wishes, much of the real world uses daylight saving time. You can get a quick primer here.
5:30 for who? If you're saying 5:30 UTC, then sure. But if you're saying 5:30 in US Central Time, then you have to take DST into account. Otherwise, half of the year people will show up at your event at what they think is 5:30 and you think is 6:30.
You're storing the times in UTC, which is good. When you display them locally, you should not ignore DST.
Yes, people don't commonly understand this. It's generally expected that if you refer to a local time, that you mean a time that is local for them. If you don't include DST in that calculation, then you will have a disagreement about what time you are talking about.
Another word of advice, you might want to consider using the TZInfo gem instead of
ActiveSupport::TimeZone
. Then you would store time zone selection using the IANA identifiers such asAmerica/Chicago
. These are recognizable outside of Rails.For some unexplained reason, the ActiveSupport folks thought they should limit time zones to the 146 values they felt were "meaningful". But they didn't explain their process, and they don't seem to be on top of maintenance. I've asked why, but haven't gotten much of a detailed response.
You may also wish to review the timezone tag wiki.