-
Couldn't load subscription status.
- Fork 358
Description
Preamble
This bug was issue (sabre-io/Baikal#1343) was initially discovered in Baikal. Attempting to import ICS file containing birthday's which were pre-1970 (Linux Epoch) would throw an error with the Postgres database regarding constraints violation. The firstOccurrence value would be set to 0 when the getTimestamp() was negative. In the database this value needed to be greater than 0 resulting in a constraint violation. The issue is minor and can be remedied easily with a modification of the constraint to accept values equal to and greater than 0. Please read the issue referenced above for more details.
Root cause
The issue was traced to this library in the following lines:
dav/lib/CalDAV/Backend/PDO.php
Lines 635 to 674 in 7183a67
| if ('VEVENT' === $componentType) { | |
| $firstOccurence = $component->DTSTART->getDateTime()->getTimeStamp(); | |
| // Finding the last occurence is a bit harder | |
| if (!isset($component->RRULE)) { | |
| if (isset($component->DTEND)) { | |
| $lastOccurence = $component->DTEND->getDateTime()->getTimeStamp(); | |
| } elseif (isset($component->DURATION)) { | |
| $endDate = clone $component->DTSTART->getDateTime(); | |
| $endDate = $endDate->add(VObject\DateTimeParser::parse($component->DURATION->getValue())); | |
| $lastOccurence = $endDate->getTimeStamp(); | |
| } elseif (!$component->DTSTART->hasTime()) { | |
| $endDate = clone $component->DTSTART->getDateTime(); | |
| $endDate = $endDate->modify('+1 day'); | |
| $lastOccurence = $endDate->getTimeStamp(); | |
| } else { | |
| $lastOccurence = $firstOccurence; | |
| } | |
| } else { | |
| $it = new VObject\Recur\EventIterator($vObject, (string) $component->UID); | |
| $maxDate = new \DateTime(self::MAX_DATE); | |
| if ($it->isInfinite()) { | |
| $lastOccurence = $maxDate->getTimeStamp(); | |
| } else { | |
| $end = $it->getDtEnd(); | |
| while ($it->valid() && $end < $maxDate) { | |
| $end = $it->getDtEnd(); | |
| $it->next(); | |
| } | |
| $lastOccurence = $end->getTimeStamp(); | |
| } | |
| } | |
| // Ensure Occurence values are positive | |
| if ($firstOccurence < 0) { | |
| $firstOccurence = 0; | |
| } | |
| if ($lastOccurence < 0) { | |
| $lastOccurence = 0; | |
| } | |
| } |
Although the issue is niche calendars should be allowed to store events that have their first occurrence before the Linux Epoch.