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

Refactor the processRecurrences method. #236

Merged
merged 22 commits into from Aug 15, 2019
Merged

Conversation

s0600204
Copy link
Collaborator

@s0600204 s0600204 commented Aug 7, 2019

What it says on the tin - rewriting the aforementioned method.

(At the point of writing) the commits of this PR can be split into four logical groupings:

  1. Prep Work (3 commits) - adding support code in preparation for...

  2. The Rewrite (9 commits) - the actual refactoring of code and logic.

  3. Post-Rewrite cleanup (8 commits) - removing code no longer used post-rewrite, and adapting the rewritten code so it runs on PHP versions prior to the 7.3.x version I was using when I was working on this.

  4. Synchronisation (1 commit) - the commits of Some cleanup of the processRecurrences method #232 were originally going to be part of this PR. However, I changed my mind and supplied them in a separate PR. Unfortunately, this caused a merge conflict. This single commit rectifies that.

For the most part, the resultant output should be similar to what it was before. However - as hinted by the fact that some tests have been uncommented - there are some differences.

One difference is that the file in the "examples" folder now generates more events than before. Or, more specifically, the "Paris Timezone Test" (lines 148-162) now recurs. This particular event has a RRULE of FREQ=WEEKLY;BYDAY=2WE. According to the spec (Page 42, Paragraph 1, towards the end of the 10th line):

The BYDAY rule part MUST NOT be specified with a numeric value when the FREQ rule part is not set to MONTHLY or YEARLY.

Whether intentionally or not, the former version of the processRecurrences() method wasn't complying with this stipulation by not generating recurrences for this event (functionally rejecting the rrule as invalid). The refactored version posts an error (to the PHP log), then strips the prefixed number and continues with that instead. However, this can be changed back to the old behaviour (of rejecting the invalid rrule and not recurring) if you prefer.

Another thing of note is that this PR resolves issue #15. That wasn't - I might point out - intentional: it's simply that the new class method used to determine which days in a month a BYDAY refers to is used by both the YEARLY frequency (which did support multiple BYDAYs (so long as a BYMONTH stanza also existed)) and the MONTHLY frequency (which didn't (but now does)).

Other perks include: no more use of strtotime (in this method anyhow); reduced code duplication; and that implementation of the other RRULE stanzas should hopefully now be easier.

…RRule identifies

(Constitutes part of a fix to issue u01jmg3#15)
This is created with full knowledge of the initial event's timezone.
Leaving behind the code that determines date sets
RFC5545, page 42, paragraph 1 states [^1]:
> The BYDAY rule part MUST NOT be specified with a numeric value when the FREQ rule part is not set to MONTHLY or YEARLY.

We now validate that, and emit an error (to the php log) in this case.

----

[^1] - https://tools.ietf.org/html/rfc5545#page-42)
(As a protected function, it's not publically accessible.)
(There is another - `$defaultWeekStart` - but I plan to use that again.)
The ics parser has a minimal php requirement of `5.3.9`.
Unfortunately, I have used syntax and features that are not supported in such an early version.
This patch removes them.

* `ImmutableDateTime` is 5.5.0+
* `ImmutableDateTime::createFromMutable` is 5.6.0+
* Class member access on cloning (`(clone $an_object)->a_member`) is 7.0+
* `DateTime::createFromImmutable` is 7.3.0+
* Permitting trailing commas in function/method calls is 7.3+
@u01jmg3
Copy link
Owner

u01jmg3 commented Aug 7, 2019

Other perks include: no more use of strtotime

🙏 💯


Will need some time to digest all your hard work but so far it is looking very good.

Copy link
Owner

@u01jmg3 u01jmg3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Happy to approve, great job

My only query:

Whether intentionally or not, the former version of the processRecurrences() method wasn't complying with this stipulation by not generating recurrences for this event (functionally rejecting the rrule as invalid). The refactored version posts an error (to the PHP log), then strips the prefixed number and continues with that instead. However, this can be changed back to the old behaviour (of rejecting the invalid rrule and not recurring) if you prefer.

  • Would this constitute a breaking change if people are reliant on the old behaviour?

@s0600204
Copy link
Collaborator Author

Thanks!


  • Would this constitute a breaking change if people are reliant on the old behaviour?

I suppose it would make it harder to notice the error, which some users could rely on to help debug their calendars...

Would you like me to amend the PR so the code rejects the invalid rule instead of trying to correct it?

@u01jmg3
Copy link
Owner

u01jmg3 commented Aug 15, 2019

Would you like me to amend the PR so the code rejects the invalid rule instead of trying to correct it?

Please but keep your changes because I think we should apply them in v3 (where I can cause breaking changes) when we bump to ≥ PHP 7.

@u01jmg3 u01jmg3 self-requested a review August 15, 2019 16:40
@u01jmg3 u01jmg3 merged commit eab301c into u01jmg3:master Aug 15, 2019
@u01jmg3 u01jmg3 added this to the v2.x.x milestone Aug 15, 2019
@s0600204 s0600204 deleted the recur_master branch August 27, 2019 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants