Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
double event issue #577
base: main
Are you sure you want to change the base?
double event issue #577
Changes from all commits
7aa157a
9eb7784
969b0c8
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the changes starting from this line till 382. Can you please explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$current_month = Carbon::createFromTimestamp($this->start, $calendar->timezone)->month; $current_year = Carbon::createFromTimestamp($this->start, $calendar->timezone)->year;
in first two lines, get the current month and current year,
`$filtered = array_filter($events, function ($events_in_day) {
foreach ($events_in_day as $event) {
This foreach block filters the events to include only those that occur within the current calendar view's start and end timestamps.
It checks if the event's start time is within the range or if the event's end time falls within the range.
The 86400 seconds (24 hours) is added to the end timestamp to include events that end at the very end of the day.`
$day_events = [];
foreach ($filtered as $timestamp => $events_in_day) {
from this line Initializes an empty array to hold events for each day. It iterates over the filtered events, creating Carbon instances for the start and end times of each event, adjusted for the calendar's timezone.
for ($day = $event_start->copy(); $day->lte($event_end); $day->addDay()) {
This loop iterates through each day from the event's start to its end.
It checks if the day falls within the current month and year.
It generates a unique key for each day (day_key) and retrieves the event's unique identifier (event_id).
If the event ends at midnight (indicating it should not be counted for that day), it skips adding that event.
If the event is not already recorded for that day, it adds it to the day_events array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foreach ($day_events as $day_key => $events) {
This final loop ensures that the events for each day are stored as a simple indexed array, removing any gaps in the keys. This is useful for consistent access to the events later in the code.
Overall, this code snippet filters and organizes calendar events based on their start and end times, ensuring that events are correctly attributed to the days they occur. It handles edge cases, such as events that span multiple days and those that end exactly at the start of a new day, to prevent double counting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to add comment which kind of case does it handle