最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - FullCalendar - Event spanning all day are one day too short - Stack Overflow

programmeradmin0浏览0评论

I'm passing to fullcalendar an event like this one:

{
     id: 31,
     title: 'Test',
     start: '2014-12-22',
     end: '2014-12-23',
     allDay: true
}

I expected to find in the calendar an event that spans two whole days, but the event is only in the 2014-12-22 slot, not in the 2014-12-23 one. The nextDayThreshold parameter is set to 00:00:00, but according to the documentation it should be ignored when allDay is set to true. I'm sure that allDay is correctly interpreted because in the agenda view the event appears in the all-day row.

How can I set fullcalendar to display such an event in both days?

I'm passing to fullcalendar an event like this one:

{
     id: 31,
     title: 'Test',
     start: '2014-12-22',
     end: '2014-12-23',
     allDay: true
}

I expected to find in the calendar an event that spans two whole days, but the event is only in the 2014-12-22 slot, not in the 2014-12-23 one. The nextDayThreshold parameter is set to 00:00:00, but according to the documentation it should be ignored when allDay is set to true. I'm sure that allDay is correctly interpreted because in the agenda view the event appears in the all-day row.

How can I set fullcalendar to display such an event in both days?

Share Improve this question edited Jun 6, 2016 at 8:28 Karl Gjertsen 4,9288 gold badges42 silver badges64 bronze badges asked Dec 22, 2014 at 14:11 SoelSoel 3632 silver badges10 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 8

Based on the eventDataTransform function you could add 1 day if your event is allDay. Note that this will only affect rendering.

eventDataTransform: function(event) {                                                                                                                                
  if(event.allDay) {                                                                                                                                               
    event.end = moment(event.end).add(1, 'days')                                                                                                                 
  }
  return event;  
}                                                                                                                                                  

I believe this a conscious design decision, in that all end dates are to be regarded as exclusive, based on discussions like this and this, i.e. so despite being an all day event, your end date is not regarded as included (inclusive) of the dates tagged. e.g. If you have a start date of 2015-03-01 00:00:00 and an end date of 2015-03-02 00:00:00 the span is only one day.

This seems to coincide with the version 2 upgrade to using moment.js. So it would appear you will either need to add '23:59:59' to your end date, or to find a a different way of specifying the end date, e.g. as a duration of two days added to the start date?

on ajax GET all events add one day

moment(end_date, 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD HH:mm:SS')

on ajax POST (update) subtract(1, 'days')

moment(eventChange_end, 'YYYY-MM-DD').subtract(1, 'days').format('YYYY-MM-DD HH:mm:SS')
发布评论

评论列表(0)

  1. 暂无评论