Skip to content

fix a bug where calculOccurence() would return dates outside the input range when called on an event with includeDates#57

Open
hlehoux2021 wants to merge 2 commits intojeedom:betafrom
hlehoux2021:beta
Open

fix a bug where calculOccurence() would return dates outside the input range when called on an event with includeDates#57
hlehoux2021 wants to merge 2 commits intojeedom:betafrom
hlehoux2021:beta

Conversation

@hlehoux2021
Copy link
Copy Markdown

Description

This PR solves the problem where calculOccurrence() would return dates outside the input range when called on an event with includeDates

Suggested changelog entry

  1. do not include in the result of calculOccurence() dates of the event that are outside the input startDate/endDate
  2. when an input range is not provided, keep dates included

Types of changes

  • Bug fix (non-breaking change which fixes)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

@hlehoux2021
Copy link
Copy Markdown
Author

Been in test since mid-december 25.

@Mips2648 Mips2648 self-requested a review April 1, 2026 08:16
@Mips2648
Copy link
Copy Markdown
Contributor

Mips2648 commented Apr 2, 2026

Could you please explain use cases causing issues?
I do see the point to not return such dates but we need to be able to reproduce to confirm the bug and the resolution, it is a bit difficult to accept PR without any background, this is probable why it is not yet validated

@hlehoux2021
Copy link
Copy Markdown
Author

Yes, thank you!
Here is the use-case i'm in:
I use calculOccurence() to evaluate if a given calendar event will occur "tomorrow".
For this i have added to data/php/user.function.class.php this function:

public static function isTomorrow($_id) {
$event = calendar_event::byId($_id);
$startDate = (new DateTime('tomorrow'))->format('Y-m-d H:i:s');
$endDate = (new DateTime('tomorrow +1 day - 1 second'))->format('Y-m-d H:i:s');
$results = $event->calculOccurrence($startDate, $endDate);
return count($results);
}

I use it in a scenario run every day early morning ;
Capture d’écran 2026-04-05 à 19 25 18

More concretly, i request the event "Present" (calendar_event id 76) in the following calendar:
Capture d’écran 2026-04-05 à 19 33 23

For instance, the expected behavior is:
on April 09 morning, calculOccurence() for this calendar event "Present" on the next day (april 10) should return 0
on April 10 morning, calculOccurence() for this calendar event "Present" on the next day (april 11) should return >0 and i will take appropriate actions to prepare my coming back home.

Note: i dont know if there is an impact: i use extensively calendar inheritance by inclusion and exclusion of other calendars, so the recursive nature of calculOccurence() is important
Here is a definition of the calendar_event "Present"
Capture d’écran 2026-04-05 à 19 42 27

I'm aware of the "somewhat" heavy calculation involved in using calculOccurence() this way ; i use it only once a day, very early when the system is quite idle.

I must also stress that i'm not at all a php expert, so please modify my PR if my code does not match the requested quality - not a problem for me to be corrected.

@Mips2648 Mips2648 self-assigned this Apr 11, 2026
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

Successfully merging this pull request may close these issues.

2 participants