Take the 2-minute tour ×

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)

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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
share|improve this answer
thanks! your answer led me to a solution –  SeanNieuwoudt Oct 14 '11 at 15:00
@Sean: please share the solution. –  tokland Oct 14 '11 at 15:03

Your Answer


