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

No API to retrieve "next" event #103

Closed
basak opened this issue Dec 6, 2022 · 3 comments
Closed

No API to retrieve "next" event #103

basak opened this issue Dec 6, 2022 · 3 comments

Comments

@basak
Copy link

basak commented Dec 6, 2022

Hi,

First, thank you for this package! I'm writing some code to handle calendar events as they occur in real time. With python-recurring-ical-events it's really easy for a user to create a recurring calendar event and have an app interacting with their calendar respond to it.

But since I'm working in real time, the "expand everything within a time span" doesn't really work for me, because the time span is constantly moving. My calendar has about 3000 objects, and constantly trying to do this even for just the next day takes on the order of minutes. Of course most of those events are in the past and don't need looking at again, but it isn't very easy to arrange that.

What would be really useful is a "get next event" method, just like what datetime.rrule.rrule.after provides. It looks like I can hack that by instantiating a RecurringEvent directly myself, and then accessing the rule attribute, which would be a dateutil.rrule.rruleset object. But, I don't think is is a formal part of the python-recurring-ical-events API, and also it would miss any changes in specific instances of the recurring set, such as in #62.

Ideally, UnfoldableCalendar would have after and before methods, just like dateutil.rrule.rrule, and would return the next or previous event relative to a given time. This would allow an app to follow events in real time. These would probably need to be implemented by considering the rule.after() (or rule.before()) against every contained RecurringEvent, considering any specific instances that override the rule, and doing some sorting. For before, one would also ideally find the event that ends most recently before the given time.

I thought I'd register this wishlist item and see if you have an opinion. I'm not sure whether to tackle this myself or not, but I wonder if this would be something you'd be willing to accept? It might require some refactoring!


We're using [Polar.sh](https://polar.sh/niccokunzmann) so you can upvote and help fund this issue. We receive the funding once the issue is completed & confirmed by you. Thank you in advance for helping prioritize & fund our work. Fund with Polar
@niccokunzmann
Copy link
Owner

niccokunzmann commented Dec 10, 2022 via email

@niccokunzmann
Copy link
Owner

niccokunzmann commented Mar 30, 2024

I added the after() method to iterate the next events. (since v2.2.0)
#130
Does this cover the expectations?
I believe, it could be faster, though.

@niccokunzmann
Copy link
Owner

I think that the after() method would do this. However, we could also add a before() method, too. I would say that if before() is required, one should open a new issue. I will close this now as finished. Please feel free to re-open/comment/open a new issue in case this needs more work. after() is an iterator which allows following an event stream in real time, requesting the next event (ordered by start) only if the start of the last event is in the past. With this, one can make sure not to miss events and handle those which are at the moment.

@basak if you would like to link your project in the related project's section, this is very welcome!

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

2 participants