开发者

How to adjust timezones in Ruby for each user's saved items

开发者 https://www.devze.com 2023-04-12 20:57 出处:网络
I have an app with the following basic workflow: Users have profiles where they get to set their local timezone (+2:00 etc).

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号