检查日期范围是否在另一个日期范围内以进行fullcalendar.io显示

编程入门 行业动态 更新时间:2024-10-11 15:17:36
本文介绍了检查日期范围是否在另一个日期范围内以进行fullcalendar.io显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在实现服务器端代码,以获取 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:

  • 事件的日期范围的任何部分是否在日历发出的可见范围内-如果是,则显示它.
  • 如果是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显示

    本文发布于:2023-11-07 19:23:50,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1567209.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:日期   范围内   io   fullcalendar

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!