Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FullCalendar end date is not inclusive

Tags:

fullcalendar

I'm using FullCalendar Beta2, and I set the AllDay flag to True. The calendar still treats End Date as exclusive! How can I make the End date inclusive?

Many thanks.

like image 824
ZooZ Avatar asked Mar 25 '14 12:03

ZooZ


1 Answers

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.

 displayEventTime: false,

Then remove the allDay tag from your event and I used a foreach loop for my events which I pulled from DB.

$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. 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

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. 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.

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.

like image 136
Alex M Avatar answered Oct 19 '22 07:10

Alex M