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

Getting first upcoming and one past occurrence? #60

Closed
buzzclue opened this issue Dec 6, 2018 · 11 comments
Closed

Getting first upcoming and one past occurrence? #60

buzzclue opened this issue Dec 6, 2018 · 11 comments

Comments

@buzzclue
Copy link

buzzclue commented Dec 6, 2018

Is there a way to get only one upcoming and past occurrence? instead of all occurrences?

@rlanvin
Copy link
Owner

rlanvin commented Dec 6, 2018

Well getOccurrences and getOcurrencesBetween get a $limit parameter, is that what you want?

@buzzclue
Copy link
Author

buzzclue commented Dec 6, 2018

I just want to get the first upcoming and last past date... getOccurrences gives all dates and i want to avoid loop to find first upcoming date.

@rlanvin
Copy link
Owner

rlanvin commented Dec 6, 2018

What about getOccurrencesBetween? getOccurrencesBetween($today, null, 1) will return 1 occurrence after today, so the first upcoming occurrence. For the past it's a bit more tricky, but maybe array_pop(getOcurrencesBetween(null,$today))? I could add some helpers, but I think this workaround should work.

@buzzclue buzzclue changed the title Getting one upcoming and one past occurrence? Getting first upcoming and one past occurrence? Dec 6, 2018
@buzzclue
Copy link
Author

buzzclue commented Dec 6, 2018

Thank you for your quick response and workaround, i will give it a try.

@buzzclue buzzclue closed this as completed Dec 6, 2018
@buzzclue buzzclue reopened this Dec 7, 2018
@buzzclue
Copy link
Author

buzzclue commented Dec 7, 2018

I have another scenario, i will be grateful if you may give me workaround? i want to get nth occurrence one way is i change the limit and array_pop like you did previously but lets say nth number is 500 or even higher in this case performance is the question especially memory?

@rlanvin
Copy link
Owner

rlanvin commented Dec 7, 2018

You would have to test the performance. To get the 500th occurrence after a date there is no other way but to calculate all occurrences to that date, and then 500 occurrences after that date (this is due to how RRULE work), which is was getOccurrencesBetween will do. That being said 500 is really a lot - even for a daily event that's almost 2 years. What is your need exactly?

@buzzclue
Copy link
Author

I have an event page where i display the current event details and navigation for next and previous occurrence. I know the chances are less or maybe none that user will get to 500th occurrence.

Follow this:

Lets say today is 20th occurrence now to get one previous date i will do $rrule->getOccurrencesBetween( null, $current ); and will get all past dates. I thought it would be easier if we can simply get nth occurrence instead?

Oh One thing previous occurrence is on second last index when we do $rrule->getOccurrencesBetween( null, $current );

Please let me know if you need more clarification? BTW loved your work.

@rlanvin
Copy link
Owner

rlanvin commented Dec 22, 2018

Yes I agree, the interface could be made easier for this use case, with some helper functions. I'll have a look when I have a moment.

Oh One thing previous occurrence is on second last index when we do $rrule->getOccurrencesBetween( null, $current );

Only if $current itself matches the rule I think?

@buzzclue
Copy link
Author

Only if $current itself matches the rule I think?

Yes that is correct.

rlanvin added a commit that referenced this issue Jan 13, 2019
@rlanvin
Copy link
Owner

rlanvin commented Jan 13, 2019

Hello, I added the helpers into master. Please check version 2.0.0-rc1 and give me your feedback!

@buzzclue
Copy link
Author

You are awesome!

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