检查日期范围是否在另一个日期范围内以进行fullcalendar.io显示 [英] Check if date range is within another date range for fullcalendar.io display

查看:61
本文介绍了检查日期范围是否在另一个日期范围内以进行fullcalendar.io显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现服务器端代码,以获取 fullcalendar.io 的事件.

I'm implementing the server side code to fetch events for fullcalendar.io.

有两种情况:

  1. 事件有开始和结束日期
  2. 活动有开始日期,并且设置为全天

型号:

public Class CalendarEvent {
  public DateTimeOffset Start { get; set; }
  public DateTimeOffset? End { get; set; }
  public bool AllDay { get; set; }
}

https://fullcalendar.io 加载视图时,它将发出日期范围,基本上是日期范围可以在日历上看到(即10/8/18到12/8/18),然后将其发送到我的控制器以获取该范围内的相关事件.

When https://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:

  1. 事件的日期范围的任何部分是否在日历发出的可见范围内-如果是,则显示它.
  2. 如果是AllDay事件,则开始日期是否在视图内?

伪示例:

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显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆