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

Unable to transform RRule to text when it has a WEEKLY frequency and no BYDAY #179

Open
markpruett571 opened this issue Jun 5, 2020 · 1 comment

Comments

@markpruett571
Copy link

Hi there!

If you try to parse a rrule with frequency set to WEEKLY and no BYDAY set, it'll give you an error:

PHP Error: Call to a member function format() on null in .../vendor/simshaun/recurr/src/Recurr/Transformer/TextTransformer.php on line 282

Sample code to reproduce the error:
echo (new \Recurr\Transformer\TextTransformer)->transform(new Recurr\Rule('FREQ=WEEKLY'));

This is on version 4.0.2

@markpruett571 markpruett571 changed the title Unable to transform to text rrule with WEEKLY frequency and no BYDAY Unable to transform RRule to text when it has a WEEKLY frequency and no BYDAY Jun 5, 2020
@jglhelias
Copy link

You're right. I faced the same situation.

As you wrote it's easy to reproduce.

$rrule = new \Recurr\Rule('FREQ=WEEKLY');
$transformer = new \Recurr\Transformer\TextTransformer();
echo $transformer->transform($rrule);

The above example will output:
Fatal error: Uncaught Error: Call to a member function format() on null in vendor\simshaun\recurr\src\Recurr\Transformer\TextTransformer.php on line 282

Except that, according to the RFC 5545 Section 3.8.2.4, you can read:

This property is REQUIRED in all types of recurring calendar components that specify the "RRULE" property.

So you must explicitelly define a start date in the constructor.

$rrule = new \Recurr\Rule('FREQ=WEEKLY', new \DateTime());
$transformer = new \Recurr\Transformer\TextTransformer();
echo $transformer->transform($rrule);

The above example will output:
weekly on Thursday

Maybe the library should warn the user that the instance lacks of a start date while a rrule is set, avoiding the transformer to throw an exception.

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