Question

I have a RoR application where I store locations using gmaps4rails. Based on the address of the location, I'd like to guess the UTC offset ("+00:00", "-05:00", ..). Is it possible or I have to ask users (and trust them) to set the correct timezone offset?

By the way, I know that there are some places where the timezone offset may change during the year. In this case, I should use the zone name instead of the offset. Is there a gem that helps to deal with these issues?

Thank you,

Was it helpful?

Solution

Geolocate the address to lat/lon coordinates using any number of web services for this. Then see the options in How to get a time zone from a location using latitude and longitude coordinates? The Ruby gem that Yevgeniy mentioned is listed there, along with other options.

Don't try to get an offset for the location - it could change periodically for DST. Get the time zone instead, such as Asia/Singapore or America/New_York. Then use that to determine the offset for a particular point in time.

See "Time Zone != Offset" in the timezone tag wiki.

OTHER TIPS

Even if you get the solution, it is better to ask them from user. If user in the US wants to see his/her datetime according to timezone in Singapore (because that is his/her homeown), he/she should be shown it like that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top