How to adjust timezones in Ruby for each user's saved items
I have an app with the following basic workflow:
- Users have profiles where they get to set their local timezone (+2:00 etc).
- Users actions are added to a job queue (mongo collection)
Firstly, I need to save items to the queue in GMT time -/+ the users timezone offset.
What would be the best way to go about doing this?
I currently have:
DateTime.parse("26 October 2011 14:45") + Rational(user.timezone.to_f, 24)
I have a suspicion that the above code isn't exactly reliable.
There is also a cron job that runs hourly and processes the jobs - I would need to query the queue for items that need to be processed at this 开发者_开发问答exact hour (minutes are not important)
Just parse "scoping" through the user's timezone:
>> ActiveSupport::TimeZone.new('Madrid').parse("26 October 2011 14:45")
=> Wed, 26 Oct 2011 14:45:00 CEST +02:00
精彩评论