1
0

EventReaderRRule.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\CalDAV;
  8. use DateTime;
  9. use DateTimeInterface;
  10. class EventReaderRRule extends \Sabre\VObject\Recur\RRuleIterator {
  11. public function precision(): string {
  12. return $this->frequency;
  13. }
  14. public function interval(): int {
  15. return $this->interval;
  16. }
  17. public function concludes(): ?DateTime {
  18. // evaluate if until value is a date
  19. if ($this->until instanceof DateTimeInterface) {
  20. return DateTime::createFromInterface($this->until);
  21. }
  22. // evaluate if count value is higher than 0
  23. if ($this->count > 0) {
  24. // temporarily store current recurrence date and counter
  25. $currentReccuranceDate = $this->currentDate;
  26. $currentCounter = $this->counter;
  27. // iterate over occurrences until last one (subtract 2 from count for start and end occurrence)
  28. while ($this->counter <= ($this->count - 2)) {
  29. $this->next();
  30. }
  31. // temporarly store last reccurance date
  32. $lastReccuranceDate = $this->currentDate;
  33. // restore current recurrence date and counter
  34. $this->currentDate = $currentReccuranceDate;
  35. $this->counter = $currentCounter;
  36. // return last recurrence date
  37. return DateTime::createFromInterface($lastReccuranceDate);
  38. }
  39. return null;
  40. }
  41. public function concludesAfter(): ?int {
  42. return !empty($this->count) ? $this->count : null;
  43. }
  44. public function concludesOn(): ?DateTime {
  45. return isset($this->until) ? DateTime::createFromInterface($this->until) : null;
  46. }
  47. public function daysOfWeek(): array {
  48. return is_array($this->byDay) ? $this->byDay : [];
  49. }
  50. public function daysOfMonth(): array {
  51. return is_array($this->byMonthDay) ? $this->byMonthDay : [];
  52. }
  53. public function daysOfYear(): array {
  54. return is_array($this->byYearDay) ? $this->byYearDay : [];
  55. }
  56. public function weeksOfYear(): array {
  57. return is_array($this->byWeekNo) ? $this->byWeekNo : [];
  58. }
  59. public function monthsOfYear(): array {
  60. return is_array($this->byMonth) ? $this->byMonth : [];
  61. }
  62. public function isRelative(): bool {
  63. return isset($this->bySetPos);
  64. }
  65. public function relativePosition(): array {
  66. return is_array($this->bySetPos) ? $this->bySetPos : [];
  67. }
  68. }