简体   繁体   English

FullCalendar 结束日期不包括在内

[英]FullCalendar end date is not inclusive

I'm using FullCalendar Beta2, and I set the AllDay flag to True.我正在使用 FullCalendar Beta2,并将 AllDay 标志设置为 True。 The calendar still treats End Date as exclusive!日历仍然将结束日期视为唯一的! How can I make the End date inclusive?如何使结束日期包含在内?

Many thanks.非常感谢。

@ZooZ - According to the Beta 2 Upgrade docs, the end date is now exclusive: @ZooZ - 根据 Beta 2 升级文档,结束日期现在是独家的:

all end dates are now exclusive.所有结束日期现在都是独占的。 For example, if an all-day event ends on a Thursday, the end date will be 00:00:00 on Friday.例如,如果全天活动在星期四结束,则结束日期将为星期五的 00:00:00。 The 1.x versions had some strange rules in regards to this. 1.x 版本在这方面有一些奇怪的规则。 Things should be much simpler now that exclusive end dates are used consistently throughout the API.由于在整个 API 中一致使用独占结束日期,因此事情应该简单得多。 In addition, this behavior is more consistent with other API's and formats, such as iCalendar.此外,此行为与其他 API 和格式(例如 iCalendar)更加一致。

Reference: http://arshaw.com/fullcalendar/wiki/Upgrading-to-2/参考: http : //arshaw.com/fullcalendar/wiki/Upgrading-to-2/

I would just add one to your end date calculation to work around this :)我只想在您的结束日期计算中添加一个来解决这个问题:)

You can hook into eventAfterAllRender and update a copy of the events and force the calendar to refresh.您可以挂钩 eventAfterAllRender 并更新事件的副本并强制刷新日历。

In my example the modification only applies to events marked as allDay events (allDay:true).在我的示例中,修改仅适用于标记为 allDay 事件 (allDay:true) 的事件。 I only modifies a copy/clone of the events data so it only changes the displaying, not the actual data ( I think - I need to test it better).我只修改事件数据的副本/克隆,所以它只更改显示,而不是实际数据(我认为- 我需要更好地测试它)。 I added the clone function but you can use something else if you like.我添加了克隆功能,但如果您愿意,您可以使用其他功能。 I added the forceRendererToDisplay flag make it run only once.我添加了 forceRendererToDisplay 标志使它只运行一次。

Here is a fiddle: https://jsfiddle.net/a3q9c5tr/15/这是一个小提琴: https : //jsfiddle.net/a3q9c5tr/15/

 function clone(obj) {
  if (null == obj || "object" != typeof obj) return obj;
  var copy = obj.constructor();
  for (var attr in obj) {
      if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
  }
  return copy;
}

$('#calendar1').fullCalendar({
forceRerenderToDisplay: true,
eventAfterAllRender: function(){
    var startdatestr = this.options.events[0].start;
    var enddatestr = this.options.events[0].end;
    if(this.options.forceRerenderToDisplay == true){
        var endDisplayDate = new Date(enddatestr);
        endDisplayDate.setDate(endDisplayDate.getDate() + 1);
        this.options.forceRerenderToDisplay = false;
      var evs = clone(this.options.events);
      for(var i in evs){
        if(evs[i].allDay){
            evs[0].end = new Date(endDisplayDate).toISOString().slice(0,10);
        }
      }
      this.calendar.removeEvents();
      this.calendar.addEventSource(evs);
      this.calendar.rerenderEvents();
    }
},
events:[
    {start:'2016-04-03',end:'2016-04-05',title:'my event', allDay:true}
],
header: {
  left: 'prev,next,today',
  center: 'title',
  right: 'month,agendaWeek,agendaDay',
  allDay:true
  }
});

I know this is kind of old now but with end dates being exclusive I found this workaround without having to add additional days.我知道这现在有点老了,但是由于结束日期是排他性的,我找到了这个解决方法,而不必添加额外的天数。 first up is set display time to false this will make it so that the time is not shown on the events.首先是将显示时间设置为false,这将使时间不显示在事件上。

 displayEventTime: false,

Then remove the allDay tag from your event and I used a foreach loop for my events which I pulled from DB.然后从您的事件中删除 allDay 标记,我对从数据库中提取的事件使用了 foreach 循环。

$events=[
 "start_date"=>"2020-01-01 00:00:00",
 "end_date"=>"2020-01-04 00:00:00",
 "title"=>"My Event",
]

events:[
<?php foreach ($events as $event):?>
<?php echo "{start:'".$event["start_date"]."',end:'".$event["end_date"]."',title:'".$event["title"]."'}},";?>
<?php endforeach;?>
],

Within the events part is where I have a foreach loop for the events.在事件部分中,我有一个事件的 foreach 循环。 I will add我会加

          <?php $date = DateTime::createFromFormat("Y-m-d H:i:s", $event["end_date"]);
             $date->setTime(0, 0);
             // Add 23 hours
             $date->add(new DateInterval('PT23H'));?>

so my final foreach loop looks like所以我最后的 foreach 循环看起来像

events:[
    <?php foreach ($events as $event):?>
      <?php $date = DateTime::createFromFormat("Y-m-d H:i:s", $event["end_date"]);
      $date->setTime(0, 0);
      // Add 23 hours
      $date->add(new DateInterval('PT23H'));?>
 <?php echo " 
 {start:'".$event["start_date"]."',end:'".$date->format('Y-m-d H:i:s')."', 
 title:'".$event["title"]."'}},";?>
  <?php endforeach;?>
 ],

so this has the foreach loop within the events.所以这在事件中有 foreach 循环。 Then I create the date in a easy format to work with where I add the 23 hours and then echo out the date formatted within the event itself.然后我以一种简单的格式创建日期,以便在其中添加 23 小时,然后回显在事件本身中格式化的日期。

This then displays the end date as inclusive without having to adjust nextDayThreshold or having to add days before adding a date to your Database.然后将结束日期显示为包含日期,而无需调整 nextDayThreshold 或在将日期添加到数据库之前添加天数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM