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

Access humanReadable from RSET? #115

Open
dtconsultingltd opened this issue Sep 24, 2022 · 3 comments
Open

Access humanReadable from RSET? #115

dtconsultingltd opened this issue Sep 24, 2022 · 3 comments

Comments

@dtconsultingltd
Copy link

HI,
I couldn't figure out how to use EXDATE with new RRule(), so I've used new RSet() instead.
This is all working, but how can I access the humanReadable() function for RSet?

My code is below. Thanks for your help and thanks for a great library!

	$rset = new RSet();
        $rset->addRRule(array(
			'FREQ' => 'weekly',
			'INTERVAL' => 1,
			'BYDAY' => 'MO, TU, WE, TH, FR',
			'DTSTART' => '2022-09-20 11:00:00',
            'UNTIL' => '2022-10-01 12:00:00'
		));
	$rset->addExdate('2022-09-22 11:00:00');

$rset->humanReadable(array('locale' => 'en-GB'));
@rlanvin
Copy link
Owner

rlanvin commented Sep 24, 2022

Hello, I'm afraid at the moment you can't. humanReadable is a method of the RRule class only, RSet (a recurrence set, combining multiple RRULE, EXRULE, DATE and EXDATE) doesn't support it. In theory it would be possible to implement a human readable version of RSet though. It would have to combine all the human readable versions of all the rules inside the sets, glued together with "and" or "except" or something like this. The result it produces might be a bit awkward in some situations but should be understandable by a human I suppose.

I might try to build it at some point, but I can't guarantee I'll have time anytime soon. If you want to look into this, feel free to submit a PR for review.

In the meantime, if you want a workaround, you could do a quick & dirty manual version for your particular use case, something like:

$rset = new RSet();
$rset->addRRule(array(
    'FREQ' => 'weekly',
    'INTERVAL' => 1,
    'BYDAY' => 'MO, TU, WE, TH, FR',
    'DTSTART' => '2022-09-20 11:00:00',
    'UNTIL' => '2022-10-01 12:00:00'
));
$rset->addExdate('2022-09-22 11:00:00');

$formatter = \IntlDateFormatter::create(
    'en-GB',
    \IntlDateFormatter::SHORT,
    \IntlDateFormatter::NONE
);

echo $rset->getRRules()[0]->humanReadable(array('locale' => 'en-GB'));
echo " except ";
echo $formatter->format($rset->getExDates()[0]);

// weekly on Monday, Tuesday, Wednesday, Thursday and Friday, starting from 20/09/2022, until 01/10/2022 except 22/09/2022

@dtconsultingltd
Copy link
Author

Thanks so much!
That worked like a dream for my simple use case where I just have a single recurring rule.
Am I right in thinking that EXDATE is only available in RSet(), and not available in RRule()?

@rlanvin
Copy link
Owner

rlanvin commented Sep 27, 2022

Yes you are correct - EXDATE and RRULE and two different properties of the iCalendar format (RFC5545). EXDATE is not part of RRULE.

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