asantibanez / livewire-resource-time-grid

Laravel Livewire component to show Events by time and resource in a good looking grid
MIT License
217 stars 42 forks source link

Conflicting neighbour events when they are not #11

Open aliowacom opened 2 years ago

aliowacom commented 2 years ago

Recently I've been testing package and found out that there's a bug with conflicting events.

All events within resource suddenly become conflicting and are rendered very narrowly. Steps to reproduce:

  1. create non conflicting events within one resource
  2. add last non conflicting event with ends_at 00:00
   public function resources()
    {
        return collect([
            ['id' => '1', 'title' => 'Meal day'],
        ]);
    }

    public function events()
    {
        return collect([
            [
                'id' => 1,
                'title' => 'Breakfast',
                'starts_at' => Carbon::today()->setTime(8, 0),
                'ends_at' => Carbon::today()->setTime(9, 0),
                'resource_id' => '1',
            ],
            [
                'id' => 2,
                'title' => 'Lunch',
                'starts_at' => Carbon::today()->setTime(12, 0),
                'ends_at' => Carbon::today()->setTime(14, 0),
                'resource_id' => '1',
            ],
            [
                'id' => 3,
                'title' => 'Dinner',
                'starts_at' => Carbon::today()->setTime(18, 0),
                'ends_at' => Carbon::today()->setTime(0, 0),
                'resource_id' => '1',
            ],
        ]);
    }
aliowacom commented 2 years ago

I was experiencing with the behaviour and it looks as follows: when ends_at is less than starts_at, it flips it and looks for conflicting events. In case with 'Dinner' example, it looks for conflicting events from 0:00 till 18:00 and finds other two. If I set 'ends_at' to '13:00', it will conflict with only one event which is 'Lunch'.

To me, there are two things to implement:

  1. make 0:00 to be treated as 23:59 when checking neighbours
  2. throw exception if ends_at is less than starts_at (except 0:00)