makzumi / laravel-calendar

Flexible Calendar for Laravel 4
58 stars 31 forks source link

If 1 of month and startingDay is not first td, the "filling" td's have wrong data-datetime and highlighting #32

Open somatonic opened 5 years ago

somatonic commented 5 years ago

In buildBody() the $day (starts with 1) doesn't get counted up for the fill days up until startingDay (1. of month).

This results in having those td's all have a data-datetime of m-01-Y. And if an event is on 1. those also get highlighted.

I changed the inner for loop to something like:

for ($j = 0; $j <= 6; $j++) {

    if ($day <= $monthLength && ($i > 0 || $j >= $startingDay)) {
        $curr_date = $this->getDayDate($day);
        $classes = [];
        if ($this->hasEvent($curr_date))
            $classes[] = 'event';
        if ($curr_date == $this->today)
            $classes[] = 'today';
        $class = count($classes) ? ' class="' . implode(' ', $classes) . '"' : '';
        $h .= "<td data-datetime='$curr_date' $class>";
        $h .= $this->dateWrap[0];
        $h .= $this->dayWrap[0];
        $h .= $day;
        $h .= $this->dayWrap[1];
        $h .= $this->buildEvents($curr_date);
        $day++;
    } else {
        $h .= "<td>";
        $h .= $this->dateWrap[0];
        $h .= "&nbsp;";
    }
    $h .= $this->dateWrap[1];
    $h .= "</td>";
}