Auto Rails Interval Based on UTC Offset and DST

I basically want to auto-determine the user's timezone using Rails. I can use this JS code in the user's browser ( http://www.onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/ ) to submit the form with a UTC offset and the fact that the time zone observes DST in summer or not in the user's time zone.

As soon as I have this information on the server, I want to select the appropriate time zone. In Rails, I can get a list of time zones with ActiveSupport :: TimeZone.all. In addition, I can filter zones using utf offset thanks to the utc_offset method. However, I do not know how to filter the time slots that perform / do not perform DST.

eg. Suppose a user lives in Amsterdam. UTC offset filtering will return Berlin, Belgrade, Madrid, etc., as well as West Central Africa. All of them, but West Central Africa, would be suitable time zones for the user in Amsterdam (as they provide the same time / date), but I need to filter out West Central Africa, which does not have daylight saving in summer.

How to do it in Rails? Also, are any of my assumptions wrong?

+4
source share
1 answer

I thought http://geokit.rubyforge.org/ would be useful. You can get the coordinates of the location of the user (or city / country). The only thing you need to do is guess the time zone based on the city / country.

+1
source

Source: https://habr.com/ru/post/1310648/


All Articles