php-rrule icon indicating copy to clipboard operation
php-rrule copied to clipboard

Access to UNTIL within occurances

Open mitsion opened this issue 5 years ago • 7 comments

First I'd like to thank you for your work on this very useful library.

This is actually not an issue, but I'd like to access the "UNTIL" property in occurrences object (which now contains only date object). I'm using your library for event entry and (miss)use the "DTSTART" and "UNTIL" for start and end timestamp, because of that I need access to the UNTIL so that I can get the correct end time (UNTIL is provided as a timestamp). I've been looking at the source and trying to find a way to add the "UNTIL" property (which is only available in the "rrule" object) to the "occurrence" object, but have failed to do so (simply don't know how to merge the property into "rlist_iterator").

mitsion avatar Jan 11 '19 06:01 mitsion

Hello,

I have had this question multiple time. The easiest way to do is it to implement a proxy class on top of RRule to convert the occurrence from DateTime objects into whatever you want.

Check the branch proxy, I created a basic example for this purpose. You just need to pass a factory method to the Proxy class. For example:

$proxy = new Proxy(
	new RRule([
		'FREQ' => 'MONTHLY',
		'COUNT' => 3,
		'BYMONTHDAY' => 31,
		'DTSTART' => '1997-09-02'
	]),
	function (\DateTimeInterface $occurrence) {
		return new \RRule\Event($occurrence, 3600);
	}
);

When you use $proxy you will get \RRule\Event objects instead of a DateTime.

Happy to get feedback. If this is useful, I'll add it to master.

rlanvin avatar Jan 13 '19 16:01 rlanvin

Hello @rlanvin,

is there any intention to include this proxy feature soon?

crantodev avatar Apr 01 '19 22:04 crantodev

@danielmoracr I'm just waiting for someone, anyone who has this use case and who wants to try it to provide some feedback. I don't have this use case myself so I don't know if the solution I wrote is useful or not. If you want to give it a try, I'm happy to support and add it to the next release if it proves useful.

rlanvin avatar Apr 02 '19 18:04 rlanvin

Hi @rlanvin, this is great, thanks for your work.

However, I found an issue with the proxy branch. Please refer to the following example code.

We're setting two events there: one that starts at 00:00 and lasts until 00:59 and another one that starts at 01:00 and lasts until 01:59. The issue is that getOccurrencesBetween( '2019-10-01 00:30:00', '2019-10-01 00:39:00' ) returns an empty array, while it should return the first event because it has intersecting times with it.

bor0 avatar Oct 17 '19 17:10 bor0

Any updates?

@bor0, @rlanvin , can you share your Proxy implementation ?

ed-fruty avatar Dec 16 '19 16:12 ed-fruty

Hey, sorry I completely missed the notification for the previous message. @ed-fruty The Proxy is a branch in this repo (called "proxy"), but it's based on an older master, I will merge master into it. @bor0 Thanks for the bug report, I'll have a look.

rlanvin avatar Dec 16 '19 19:12 rlanvin

@rlanvin I gave this another try, seems to be working fine! I had an error in my implementation. I updated the Gist and it works fine.

Any chance of merging proxy into master? :)

bor0 avatar Apr 05 '20 19:04 bor0