Reputation: 235
I'd implemented timezone drop down for my project and the values will be stored in database, take for instance i'm in asia/chennai, then the value stored will be GMT +05:30, so when someone from jerusalem checks the database, they'd see my timezone value, rather it should be theirs (GMT +02:00). How to convert the specified value using ruby on rails ?
Upvotes: 0
Views: 122
Reputation: 2946
The easiest way is probably to add a timezone to your user model so that your users can set their timezone. You can do this by using the timezone gem https://github.com/panthomakos/timezone
After you have done this, converting a timestamp to their local zone should be as simple as doing:
timestamp.in_time_zone(current_user.time_zone)
(this is assuming you have a method current_user
)
Upvotes: 2