计算给定可用性和现有预约的开放时间段 - 按天
概述:
我有一个表,存储一个人当天的“可用性”,例如
周一 - 上午 8:00 - 上午 11:30
周一 - 下午 1:30 - 下午 6:00
第二个表存储此人当天已有的约会,例如
周一 - 上午 8:30 - 上午 11:00
周一 - 下午 2:30 - 下午 4 点
期望结果:
进行计算我希望得到以下结果 - 例如“此人在指定日期有空”:
周一 - 上午 8:00 - 上午 8:30
周一 - 上午 11:00 - 上午 11:30
周一 - 下午 1:30 - 下午 2:30
周一 - 下午 4:00 - 下午 6:00
如果有任何有关如何计算给定两个输入(例如可用性、现有预约)的输出的想法,我们将不胜感激。最好我在客户端上使用 javascript 来进行计算,因为我相信在数据库中进行计算(我使用 MSSQL)对于许多记录、人员等来说会很慢。
希望这是足够的信息来说明问题手头 - 非常感谢。
Overview:
I have a table which stores a persons "availability" for a current day, e.g.
Mon - 8:00am - 11:30am
Mon - 1:30pm - 6:00pm
A second table stores appointments that this person already has for the same day, e.g.
Mon - 8:30am - 11:00am
Mon - 2:30pm - 4pm
Desired result:
Doing calculationsI'd like to have the following result - e.g. "this person has availability on the given day":
Mon - 8:00am - 8:30am
Mon - 11:00am - 11:30am
Mon - 1:30pm - 2:30pm
Mon - 4:00pm - 6:00pm
Any ideas on how to calculate the output given the two inputs (e.g. availability, existing appointments) would be greatly appreciated. Preferably I'd use javascript on the client to do the calculating as I would believe that doing it within the DB (I'm using MSSQL) would be slow for many records, persons, etc.
Hope this is enough information to illustrate the problem at hand - Many thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你需要离散化你的时间。选择一个时间间隔用作原子。根据您的示例,这可能应该是半小时。
现在
我省略了主键,并且应该有外键来查找 Person 和 Interval 的表。
将有一个 Interval 表用于查找每个 Interval_id 代表什么。
将日历中的每个间隔填充到间隔表中。填充它可能是一件苦差事,但您可以在 Excel 中创建实际值,然后将它们粘贴到间隔表中。
现在您可以找到空闲间隔,因为
MSSQL 可以立即执行这种外连接(前提是您设置了键),并且您可以在发送的页面中包含空闲间隔列表,并使用 javascript 来显示它们:想要的。
You need to discretize your time. Choose a time interval to use as your atom. Based on your example, that should probably be a half hour.
Now
I'm leaving out the primary keys, and there should be foreign keys to lookup tables for Person and Interval.
There will be an Interval table for looking up what each interval_id stands for.
Populate the Interval table with every interval you're going to have in your calendar. Populating it might be a chore, but you can create the actual values in Excel, then paste them into your Interval table.
Now you can find free intervals as
MSSQL can do this kind of outer join in no time (provided you set up the keys), and you can include the list of free intervals in the pages you send, with javascript to display them when and as desired.