javascript - 如何将全日历重复事件的结束时间延长到第二天?

标签 javascript fullcalendar fullcalendar-4

如何显示结束时间超过当天的重复事件?

这是一个示例数据:

const data = {
  id: 1,
  title: "ABC",
  startRecur: "2020-06-11T16:00:00.000Z",
  startTime: "23:00:00",
  endTime: "03:00:00",
  daysOfWeek: ["5"]
};

calendar.addEventSource({
  events: [data]
});

基本上,开始时间为11:00 PM,并应在第二天3:00 AM结束。我如何让 fullcalendar 知道它应该在第二天结束?请注意,这是一个重复发生的事件。

这是月 View 中的样子:

enter image description here

在周 View 中(事件未呈现,因为它认为结束时间是同一天的凌晨 3 点):

enter image description here

Here's a pen of the problem.

我希望它看起来像这样(谷歌日历)

enter image description here

更新:使用rrule plugin让它工作

最佳答案

所以之前,我使用 fullcalendar 内置的重复事件来完成此操作。

const data = {
  id: 1,
  title: "ABC",
  startRecur: "2020-06-11T16:00:00.000Z",
  startTime: "23:00:00",
  // endTime is 03:00:00 because I expect it to end the next day at 3 AM
  endTime: "03:00:00",
  daysOfWeek: ["5"]
};

calendar.addEventSource({
  events: [data]
});

这样做的问题是,当您的 endTime 小于给定的 startTime 时,fullcalendar 将无法理解它并会不在日历中呈现该事件。

为了解决这个问题,有一个名为 rrule plugin 的插件。允许跨天重复发生事件。感谢ADyson .

我们可以使用以下方法来代替上述添加重复事件的方法:

const data = {
  id: 1,
  title: "my recurring event",
  rrule: {
    freq: "weekly",
    interval: 5,
    byweekday: ["fr"],
    // In the above code,
    // start date and start time are separate.
    // In the rrule plugin, dtstart
    // should contain both start date and time.
    dtstart: "2020-06-01T23:00:00"
  },

  // Duration is how long the event will run,
  // not exactly what the time it should end.
  // in our case, to end the event the next day 3 AM.
  // We should add 4 hours.
  duration: "04:00"
};

calendar.addEventSource({
  events: [data]
});

这是一个工作 pen .

关于javascript - 如何将全日历重复事件的结束时间延长到第二天?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62210362/

相关文章:

javascript - beforeShowMonth 在 Bootstrap 日期选择器中不起作用

javascript - 将 Firebase 值插入下拉列表

javascript - 动态添加事件到事件源

javascript - 全日历 v4 : addEvent() not working in custom view

javascript - 将 FullCalendar 集成到 Apache Royale 中

javascript日期验证检查

javascript - Karma + ui-router 失败 : Cannot read property 'isDefined' of undefined

javascript - 为什么 fullcalendar 不在模式内部渲染,但在没有模式的情况下渲染

jquery - 通过添加和删除多个事件源来过滤事件

javascript - 根据完整日历日 View 中的数据显示时段