我正在实现服务器端代码,以获取 fullcalendar.io 的事件.
I'm implementing the server side code to fetch events for fullcalendar.io.
有两种情况:
型号:
public Class CalendarEvent { public DateTimeOffset Start { get; set; } public DateTimeOffset? End { get; set; } public bool AllDay { get; set; } }当 fullcalendar.io 加载视图时,它将发出日期范围,基本上是日期范围可以在日历上看到(即10/8/18到12/8/18),然后将其发送到我的控制器以获取该范围内的相关事件.
When fullcalendar.io loads a view, it emits a date range, which is basically the days that can be seen on the calendar (i.e. 10/8/18 to 12/8/18) and I send that to my controller to fetch relevant events for that range.
我基本上需要检查以下内容:
I basically need to check the following:
伪示例:
var rep = context.GetRepository<Event>(); events = rep.Get().Where(e => /* need help here */).AsQueryable();推荐答案
我喜欢这个(重叠的日期)!通常,公式为:
I like this one (overlapping dates)! In general the formula is:
var dateFrom = ;// start of week var dateTo = ; // end of week var events = rep.Get() .Where(e => e.Start <= dateTo && e.End >= dateFrom) .AsQueryable();因为您需要范围内包含的东西,从范围开始并向外扩展,在范围之前开始并在范围内结束,并且在范围之前和之后开始.
Because you need things contained by the range, starting in the range and extending out, starting before the range and ending in, and starting before and ending after the range.
但是,如果您需要处理nullable .End,则可能更像:
But if you need to handle a nullable .End then maybe more like:
var dateFrom = ;// start of week var dateTo = ; // end of week var events = rep.Get() .Where(e => e.Start <= dateTo && (e.End ?? e.Start) >= dateFrom) .AsQueryable();(非常)基本的样机,以帮助可视化:
(very) rudimentary mockup to help visualize:
更多推荐
检查日期范围是否在另一个日期范围内以进行fullcalendar.io显示
发布评论