Skip to content

Commit d8278f2

Browse files
committed
RE: #213 - wording
Coding standards
1 parent 429cdec commit d8278f2

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- PHP 5 (≥ 5.3.0)
1212
- [Valid ICS](https://icalendar.org/validator.html) (`.ics`, `.ical`, `.ifb`) file
1313
- [IANA](https://www.iana.org/time-zones), [Unicode CLDR](http://cldr.unicode.org/translation/timezones) or [Windows](https://support.microsoft.com/en-ca/help/973627/microsoft-time-zone-index-values) Time Zones
14-
- Windows Time Zones will need the `$replaceWindowsTimeZoneIds = true` configuration
14+
- If Windows time zones are present you will need to set `$replaceWindowsTimeZoneIds` to `true`
1515

1616
### Setup
1717

@@ -66,14 +66,15 @@
6666

6767
---
6868

69-
## On parsing iCal
70-
Parsing [iCal/iCalendar/ICS](https://en.wikipedia.org/wiki/ICalendar) resources poses several challenges. One is that
71-
the specification is a moving target; the original RFC was updated four times in ten years. The other is that vendors
69+
## When Parsing an iCal Feed
70+
71+
Parsing [iCal/iCalendar/ICS](https://en.wikipedia.org/wiki/ICalendar) resources can pose several challenges. One challenge is that
72+
the specification is a moving target; the original RFC has only been updated four times in ten years. The other challenge is that vendors
7273
were both liberal (read: creative) in interpreting the specification and productive implementing proprietary extensions.
7374

7475
However, what impedes efficient parsing most directly are recurrence rules for events. This library parses the original
7576
calendar into an easy to work with memory model. This requires that each recurring event is expanded or exploded. Hence,
76-
a single event that occurs daily will generate a new event instance for every day when this parser processes the
77+
a single event that occurs daily will generate a new event instance for each day as this parser processes the
7778
calendar ([`$defaultSpan`](#variables) limits this). To get an idea how this is done take a look at the
7879
[call graph](https://user-images.githubusercontent.com/624195/45904641-f3cd0a80-bded-11e8-925f-7bcee04b8575.png).
7980

@@ -82,24 +83,24 @@ large calendars tend to get huge when exploded i.e. with all their recurrence ru
8283
old calendars do not remove past events as they get fatter and fatter every year.
8384

8485
This limitation is particularly painful if you only need a window into the original calendar. It seems wasteful to parse
85-
the entire fully exploded calendar into memory if you later are going to call the
86+
the entire fully exploded calendar into memory if you later are going to call the
8687
[`eventsFromInterval()` or `eventsFromRange()`](#methods) on it.
8788

88-
In late 2018 [#190](https://github.com/u01jmg3/ics-parser/pull/190) added the option to drop all events outside a given
89-
range very early in the parse process at the cost of some precision (timezone calculations not done at that point). This
90-
massively reduces the total time for parsing a calendar. Same goes for memory consumption of course. Precondition is that
89+
In late 2018 [#190](https://github.com/u01jmg3/ics-parser/pull/190) added the option to drop all events outside a given
90+
range very early in the parsing process at the cost of some precision (time zone calculations are not calculated at that point). This
91+
massively reduces the total time for parsing a calendar. The same goes for memory consumption. The precondition is that
9192
you know upfront that you don't care about events outside a given range.
9293

93-
Let's say your are only interested in events from yesterday, today and tomorrow. To compensate for the fact that the
94-
tricky timezone transformations and calculations have not been executed yet by the time the parser has to decide whether
95-
to keep or drop an event you tell it to filter for **+-2d** instead of +-1d. Once it is done you would then call
94+
Let's say you are only interested in events from yesterday, today and tomorrow. To compensate for the fact that the
95+
tricky time zone transformations and calculations have not been executed yet by the time the parser has to decide whether
96+
to keep or drop an event you can set it to filter for **+-2d** instead of +-1d. Once it is done you would then call
9697
`eventsFromRange()` with +-1d to get precisely the events in the window you are interested in. That is what the variables
9798
[`$filterDaysBefore` and `$filterDaysAfter`]((#variables)) are for.
9899

99-
In Q1 2019 [#213](https://github.com/u01jmg3/ics-parser/pull/213) further improved the performance by immediately
100-
dropping _non-recurring_ events once parsed if they are outside that fuzzy window. This greatly reduces the maximum
101-
memory consumption for large calendars. PHP by default does not allocate more than 128MB heap and would otherwise crash
102-
with `Fatal error: Allowed memory size of 134217728 bytes exhausted`. It goes without saying that recurring events first
100+
In Q1 2019 [#213](https://github.com/u01jmg3/ics-parser/pull/213) further improved the performance by immediately
101+
dropping _non-recurring_ events once parsed if they are outside that fuzzy window. This greatly reduces the maximum
102+
memory consumption for large calendars. PHP by default does not allocate more than 128MB heap and would otherwise crash
103+
with `Fatal error: Allowed memory size of 134217728 bytes exhausted`. It goes without saying that recurring events first
103104
need to be evaluated before non-fitting events can be dropped.
104105

105106
---

src/ICal/ICal.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,9 @@ protected function initLines(array $lines)
645645
if ($this->shouldFilterByWindow) {
646646
$this->removeLastEventIfOutsideWindowAndNonRecurring();
647647
}
648+
648649
$component = 'VCALENDAR';
649-
break;
650+
break;
650651

651652
default:
652653
$this->addCalendarComponentWithKeyAndValue($component, $keyword, $value);
@@ -688,14 +689,13 @@ protected function initLines(array $lines)
688689
* Removes the last event (i.e. most recently parsed) if its start date is outside the window spanned by
689690
* `$windowMinTimestamp` / `$windowMaxTimestamp`.
690691
*
691-
* @throws \Exception
692+
* @return void
692693
*/
693694
protected function removeLastEventIfOutsideWindowAndNonRecurring()
694695
{
695696
$events = $this->cal['VEVENT'];
696697

697698
if (!empty($events)) {
698-
699699
$lastIndex = sizeof($events) - 1;
700700
$lastEvent = $events[$lastIndex];
701701

@@ -721,6 +721,7 @@ protected function reduceEventsToMinMaxRange()
721721
foreach ($events as $key => $anEvent) {
722722
if ($this->isEventStartOutsideWindow($anEvent)) {
723723
$this->eventCount--;
724+
724725
unset($events[$key]);
725726

726727
continue;
@@ -737,7 +738,6 @@ protected function reduceEventsToMinMaxRange()
737738
*
738739
* @param array $event
739740
* @return boolean
740-
* @throws \Exception
741741
*/
742742
protected function isEventStartOutsideWindow(array $event)
743743
{

0 commit comments

Comments
 (0)