I am building a Rails application where users can post the interview details they know.The form has a input field interview time which is date time selector.I want to give universal support to this application.
Actual problem:
Let us say I have configured the IST time zone in my production server.Then if a user from Japan selects an interview time which will be parsed in IST time zone.The result will be an incorrect interview time.
To display the correct interview time.
1.Do I need to get the time zone from the user?(probably a select box)
2.Is there is any other option to automatically detect the time zone?
Thank you folks 🙂
If something is unclear please add a comment below the question.
I’ve got a similar issue. I kept the default rails config so all times are stored in UTC in the DB, and I used the following methods from ActiveSupport::TimeZone :
when I need to save a date from a form, I used
local_to_utcto convert the date from local to UTC:when I need to display a date from the DB, I used
This way all dates saved in the DB are in UTC, but are handled by the users in local time, that can be different for each user. You can store the timezone at
Userlevel (astringfield in the DB), and/or use a select helper to generate a select field.