用户的属性是start_time
、end_time
和time_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