Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception Livewire Calendar not correctly configured. Check initial inputs. #22

Open
rsimonru opened this issue Oct 1, 2021 · 11 comments

Comments

@rsimonru
Copy link

rsimonru commented Oct 1, 2021

Hello.

I'm ussing your calendar component and when show the october's calendar, show the exception "Livewire Calendar not correctly configured. Check initial inputs". I'd checked the code and when you calculate days in vendor/asantibanez/livewire-calendar/src/LivewireCalendar.php:179, the result is 36 because at end of october is the daylight saving time change and gridStartsAt is 2021-09-27 00:00:00.0 +02:00 and gridEndsAt is 2021-10-31 23:59:59.0 +01:00

Please, can you check this?

@ghost
Copy link

ghost commented Oct 1, 2021

Same problem here

@ghost
Copy link

ghost commented Oct 1, 2021

image
Forcing the timezone to the correct one solves the problem

@ghost
Copy link

ghost commented Oct 1, 2021

You also need to change lines :152 and :144 or when you go back or go next month it will not render the last day of the month neither the start of week
image

@rsimonru
Copy link
Author

rsimonru commented Oct 1, 2021

Pedro, thanks for the info.

I'd modified in my component that extend LivewireCalendar and I didn't touched the original component.
Only add this in the events method:

public function events() : Collection
{
$this->gridStartsAt->shiftTimezone(config('app.timezone'));
$this->gridEndsAt->shiftTimezone(config('app.timezone'));

....
}

@ghost
Copy link

ghost commented Oct 1, 2021

Pedro, thanks for the info.

I'd modified in my component that extend LivewireCalendar and I didn't touched the original component. Only add this in the events method:

public function events() : Collection { $this->gridStartsAt->shiftTimezone(config('app.timezone')); $this->gridEndsAt->shiftTimezone(config('app.timezone'));

.... }

That solves the first problem didn't even remembered that was a shared var 😆

However the end of grid keeps cutting last week when going back or forward

On Mount Work Fine
image

After going back and foward or vice versa
image

Wouldn't be bether to always get the endsAt from the startsAt insted of adding and subbing the months? 🤔

@ghost
Copy link

ghost commented Oct 1, 2021

Setting $this->endsAt = $this->startsAt->clone()->endOfMonth()->startOfDay(); on 'goToPreviousMonth', 'goToNextMonth' and 'goToCurrentMonth' solves the problem, so i think the problem lies on the way carbon is subbing and adding on the last day of month

@rsimonru
Copy link
Author

rsimonru commented Oct 1, 2021

You are right. The component miscalculates the end of the month.

@JuanDeLeon
Copy link

Same issue. For some reason, the diffInWeeks and diffInDays initially yields the correct results on mount (6 and 42 respectively), but after any livewire action is triggered, the result is now 7 and 43, which will throw the exception.

@jouniikaheimo
Copy link

i have the problem fixed when i added the component..

<livewire:appointments-calendar
 year="{{ now()->year }}"
 month="{{ now()->month }}"
/>

@craig-stanfield
Copy link

craig-stanfield commented Oct 4, 2023

in my case this started only today (October again though), I updated to latest version (2.2.0) but bug persists. My fix was to copy the new calculateGridStartsEnds into my component and change to this:

    public function calculateGridStartsEnds()
    {
        $this->gridStartsAt = $this->startsAt->clone()->startOfWeek($this->weekStartsAt)->shiftTimezone(config('app.timezone'));
        $this->gridEndsAt = $this->endsAt->clone()->endOfWeek($this->weekEndsAt)->shiftTimezone(config('app.timezone'));
    }

As above account for timezone. I think not only is this the months moving from single to double digits but theres the clocks also change, my app went live in December.

@datashaman
Copy link

datashaman commented Sep 6, 2024

I made this change in monthGrid which fixed things.

$numbersOfWeeks = (int) $firstDayOfGrid->diffInWeeks($lastDayOfGrid) + 1;
$days = (int) $firstDayOfGrid->diffInDays($lastDayOfGrid) + 1;

I swapped around first and last diff so the results were positive.
Then saw it was returning a fraction. Casting toint made everything work.
It probably does need a shift to the app (or better, the user) timezone. I haven't done that yet.

EDIT It's likely that Laravel sets the timezone on Carbon from config already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants