I have a Rails app for bands. Bands can import their shows which all occur in different time zones. It seems like a ton of work to store these events in UTC. I would have to figure out the time zone for any show created and then convert back to the show’s local time zone when displaying to the user. Is there a simple plugin to get a UTC offset based on geolocation? That would probably help, but does anyone see any major reasons why I should store in UTC here? I understand storing timestamps in UTC is probably a good idea…but band event times?
Share
I’m working on something similar – a site with a list of events. In my situation, it’s important to have the times standardized (in UTC) because we have announce and on-sale times to worry about (i.e., when the events appear on the site and when the on-sale links show up), not just displaying the event start time (which itself doesn’t care what time zone it’s in).
Going from a UTC time in the database to the local time for the given venue (i.e., to display the local time in the event listing) is pretty simple using something along the lines of
e.start.in_time_zone("#{e.venue.time_zone}"). What I couldn’t figure out was getting the local time at the point of data entry recognized as a local time needed to be converted to UTC, without having to deal with changing Time.zone.I found something that works. Check out this post: http://steveluscher.com/archives/changing-a-times-zone-in-rails-keeping-the-same-local-representation. I added a new file (time_zone_support.rb) to my config/initializers directory. Here are the contents:
This allows the following in the console:
Hope that helps you too!