指示时间范围的 params 字符串
sched = "8:00AM-5:30PM"
我的数据库中存储了开始和结束时间
client1.sched_start # => 2000-01-01 07:30:00 UTC
client1.sched_end # => 2000-01-01 17:30:00 UTC
client2.sched_start # => 2000-01-01 08:30:00 UTC
client2.sched_end # => 2000-01-01 16:30:00 UTC
如何测试客户端时间范围是否在计划的时间范围内,返回 true 或 false?
到目前为止,我有这个,但我总是得到正确的和弃用警告,而且它真的很慢。
time_open = Time.use_zone('UTC'){Time.zone.parse '2000-01-01 '+sched.split("-")[0]}
time_close = Time.use_zone('UTC'){Time.zone.parse '2000-01-01 '+sched.split("-")[1]}
range = time_open..time_close
range === client1.sched_start && range === client1.sched_end
range === client2.sched_start && range === client2.sched_end
这是警告的摘录
warning: Time#succ is obsolete; use time + 1
此外,时间是不同的格式。例如,
time_open # Sat, 01 Jan 2000 08:00:00 UTC 00:00
到目前为止,这些都是有帮助的: