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

RSet supporting mixed RRule's and ExRule's #48

Closed
Tam opened this issue Apr 5, 2018 · 2 comments
Closed

RSet supporting mixed RRule's and ExRule's #48

Tam opened this issue Apr 5, 2018 · 2 comments

Comments

@Tam
Copy link

Tam commented Apr 5, 2018

It would be really useful if RSet's could support having a mix of RRule's and ExRule's, where subsequent rules would override previous ones.

For example:

use RRule\RSet;

$set = new RSet();

$set->addRRule([
	'FREQ' => 'HOURLY',
	'DTSTART' => '20180404T080000Z',
	'UNTIL' => '20180405T160000Z',
]);

$set->addExRule([
	'FREQ' => 'HOURLY',
	'DTSTART' => '20180404T160000Z',
	'UNTIL' => '20180405T080000Z',
]);

$set->addRRule([
	'FREQ' => 'HOURLY',
	'DTSTART' => '20180404T180000Z',
	'UNTIL' => '20180405T020000Z',
]);

foreach ($set as $date)
	echo $date->format('r'), "\n";

Would ideally output:

Wed, 04 Apr 2018 08:00:00 +0000
Wed, 04 Apr 2018 09:00:00 +0000
Wed, 04 Apr 2018 10:00:00 +0000
Wed, 04 Apr 2018 11:00:00 +0000
Wed, 04 Apr 2018 12:00:00 +0000
Wed, 04 Apr 2018 13:00:00 +0000
Wed, 04 Apr 2018 14:00:00 +0000
Wed, 04 Apr 2018 15:00:00 +0000
Wed, 04 Apr 2018 18:00:00 +0000
Wed, 04 Apr 2018 19:00:00 +0000
Wed, 04 Apr 2018 20:00:00 +0000
Wed, 04 Apr 2018 21:00:00 +0000
Wed, 04 Apr 2018 22:00:00 +0000
Wed, 04 Apr 2018 23:00:00 +0000
Thu, 05 Apr 2018 00:00:00 +0000
Thu, 05 Apr 2018 01:00:00 +0000
Thu, 05 Apr 2018 02:00:00 +0000
Thu, 05 Apr 2018 09:00:00 +0000
Thu, 05 Apr 2018 10:00:00 +0000
Thu, 05 Apr 2018 11:00:00 +0000
Thu, 05 Apr 2018 12:00:00 +0000
Thu, 05 Apr 2018 13:00:00 +0000
Thu, 05 Apr 2018 14:00:00 +0000
Thu, 05 Apr 2018 15:00:00 +0000
Thu, 05 Apr 2018 16:00:00 +0000

Where currently it outputs:

Wed, 04 Apr 2018 08:00:00 +0000
Wed, 04 Apr 2018 09:00:00 +0000
Wed, 04 Apr 2018 10:00:00 +0000
Wed, 04 Apr 2018 11:00:00 +0000
Wed, 04 Apr 2018 12:00:00 +0000
Wed, 04 Apr 2018 13:00:00 +0000
Wed, 04 Apr 2018 14:00:00 +0000
Wed, 04 Apr 2018 15:00:00 +0000
Thu, 05 Apr 2018 09:00:00 +0000
Thu, 05 Apr 2018 10:00:00 +0000
Thu, 05 Apr 2018 11:00:00 +0000
Thu, 05 Apr 2018 12:00:00 +0000
Thu, 05 Apr 2018 13:00:00 +0000
Thu, 05 Apr 2018 14:00:00 +0000
Thu, 05 Apr 2018 15:00:00 +0000
Thu, 05 Apr 2018 16:00:00 +0000

The difference:

Wed, 04 Apr 2018 08:00:00 +0000
Wed, 04 Apr 2018 09:00:00 +0000
Wed, 04 Apr 2018 10:00:00 +0000
Wed, 04 Apr 2018 11:00:00 +0000
Wed, 04 Apr 2018 12:00:00 +0000
Wed, 04 Apr 2018 13:00:00 +0000
Wed, 04 Apr 2018 14:00:00 +0000
Wed, 04 Apr 2018 15:00:00 +0000
- Wed, 04 Apr 2018 18:00:00 +0000
- Wed, 04 Apr 2018 19:00:00 +0000
- Wed, 04 Apr 2018 20:00:00 +0000
- Wed, 04 Apr 2018 21:00:00 +0000
- Wed, 04 Apr 2018 22:00:00 +0000
- Wed, 04 Apr 2018 23:00:00 +0000
- Thu, 05 Apr 2018 00:00:00 +0000
- Thu, 05 Apr 2018 01:00:00 +0000
- Thu, 05 Apr 2018 02:00:00 +0000
Thu, 05 Apr 2018 09:00:00 +0000
Thu, 05 Apr 2018 10:00:00 +0000
Thu, 05 Apr 2018 11:00:00 +0000
Thu, 05 Apr 2018 12:00:00 +0000
Thu, 05 Apr 2018 13:00:00 +0000
Thu, 05 Apr 2018 14:00:00 +0000
Thu, 05 Apr 2018 15:00:00 +0000
Thu, 05 Apr 2018 16:00:00 +0000

I'm not sure how inline this is with the spec, but it would definitely be a useful feature for advanced event generation.

@rlanvin
Copy link
Owner

rlanvin commented Apr 6, 2018

Well I have good news for you, it's already possible - albeit, as you mentioned, absolutely not supported by the spec (but then again, the whole RSet deviate from the spec quite a bit anyway).

$set = new RSet();

$subset = new RSet();
$subset->addRRule([
	'FREQ' => 'HOURLY',
	'DTSTART' => '20180404T080000Z',
	'UNTIL' => '20180405T160000Z',
]);

$subset->addExRule([
	'FREQ' => 'HOURLY',
	'DTSTART' => '20180404T160000Z',
	'UNTIL' => '20180405T080000Z',
]);

$set->addRRule([
	'FREQ' => 'HOURLY',
	'DTSTART' => '20180404T180000Z',
	'UNTIL' => '20180405T020000Z',
]);
$set->addRRule($subset);

foreach ($set as $date) {
	echo $date->format('r'), "\n";
}

@Tam
Copy link
Author

Tam commented Apr 6, 2018

Awesome!

@Tam Tam closed this as completed Apr 6, 2018
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