如何在轨道上的红宝石中管理不同的time_zones



用户的属性是start_timeend_timetime_zone

我只保存时间而不是日期和用户time_zone例如

start_time => "09:00"
end_time => "02:00"
time_zone => "Samoa"

用户仅在给定start_time和根据给定time_zone end_time称为黑白。我如何检查这个?

我的研究,我发现了这个

in_time_zone('Eastern Time (US & Canada)')

我想根据用户的start_time检查用户是否可用,并根据time_zone end_time

server_tz = Time.zone # zone on server
server_now = server_tz.now # time on server right now
Time.use_zone(time_zone) do # ⇐ user’s time zone, 'Samoa'
  server_start, server_end = %i|start_time end_time|.map do |t|
    # ⇓ parse in user time zone and convert to server tz
    Time.zone.parse("#{Date.today} #{t}").in_time_zone(server_tz)
  end
  # ⇓ use case-triple-equal to check if time is in between
  (server_start..server_end) === server_now
end

相关内容

  • 没有找到相关文章

最新更新