diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:30:08 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:30:08 +0000 |
commit | 4ce65d59ca91871cfd126497158200a818720bce (patch) | |
tree | e277def01fc7eba7dbc21c4a4ae5576e8aa2cf1f /vendor/simshaun/recurr/src/Recurr/RecurrenceCollection.php | |
parent | Initial commit. (diff) | |
download | icinga-php-library-96ecad332d1684426665842bfcebf1aa4692a020.tar.xz icinga-php-library-96ecad332d1684426665842bfcebf1aa4692a020.zip |
Adding upstream version 0.13.1.upstream/0.13.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/simshaun/recurr/src/Recurr/RecurrenceCollection.php')
-rw-r--r-- | vendor/simshaun/recurr/src/Recurr/RecurrenceCollection.php | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/vendor/simshaun/recurr/src/Recurr/RecurrenceCollection.php b/vendor/simshaun/recurr/src/Recurr/RecurrenceCollection.php new file mode 100644 index 0000000..e1e676b --- /dev/null +++ b/vendor/simshaun/recurr/src/Recurr/RecurrenceCollection.php @@ -0,0 +1,153 @@ +<?php + +/* + * Copyright 2014 Shaun Simmons + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Recurr; + +use \Doctrine\Common\Collections\ArrayCollection as BaseCollection; + +/** + * @package Recurr + * @author Shaun Simmons <shaun@envysphere.com> + */ +class RecurrenceCollection extends BaseCollection +{ + /** + * @param \DateTimeInterface $after + * @param \DateTimeInterface $before + * @param bool $inc Include $after or $before if they happen to be a recurrence. + * + * @return RecurrenceCollection + */ + public function startsBetween(\DateTimeInterface $after, \DateTimeInterface $before, $inc = false) + { + return $this->filter( + function ($recurrence) use ($after, $before, $inc) { + /** @var $recurrence Recurrence */ + $start = $recurrence->getStart(); + + if ($inc) { + return $start >= $after && $start <= $before; + } + + return $start > $after && $start < $before; + } + ); + } + + /** + * @param \DateTimeInterface $before + * @param bool $inc Include $before if it is a recurrence. + * + * @return RecurrenceCollection + */ + public function startsBefore(\DateTimeInterface $before, $inc = false) + { + return $this->filter( + function ($recurrence) use ($before, $inc) { + /** @var $recurrence Recurrence */ + $start = $recurrence->getStart(); + + if ($inc) { + return $start <= $before; + } + + return $start < $before; + } + ); + } + + /** + * @param \DateTimeInterface $after + * @param bool $inc Include $after if it a recurrence. + * + * @return RecurrenceCollection + */ + public function startsAfter(\DateTimeInterface $after, $inc = false) + { + return $this->filter( + function ($recurrence) use ($after, $inc) { + /** @var $recurrence Recurrence */ + $start = $recurrence->getStart(); + + if ($inc) { + return $start >= $after; + } + + return $start > $after; + } + ); + } + + /** + * @param \DateTimeInterface $after + * @param \DateTimeInterface $before + * @param bool $inc Include $after or $before if they happen to be a recurrence. + * + * @return RecurrenceCollection + */ + public function endsBetween(\DateTimeInterface $after, \DateTimeInterface $before, $inc = false) + { + return $this->filter( + function ($recurrence) use ($after, $before, $inc) { + /** @var $recurrence Recurrence */ + $end = $recurrence->getEnd(); + + if ($inc) { + return $end >= $after && $end <= $before; + } + + return $end > $after && $end < $before; + } + ); + } + + /** + * @param \DateTimeInterface $before + * @param bool $inc Include $before if it is a recurrence. + * + * @return RecurrenceCollection + */ + public function endsBefore(\DateTimeInterface $before, $inc = false) + { + return $this->filter( + function ($recurrence) use ($before, $inc) { + /** @var $recurrence Recurrence */ + $end = $recurrence->getEnd(); + + if ($inc) { + return $end <= $before; + } + + return $end < $before; + } + ); + } + + /** + * @param \DateTimeInterface $after + * @param bool $inc Include $after if it a recurrence. + * + * @return RecurrenceCollection + */ + public function endsAfter(\DateTimeInterface $after, $inc = false) + { + return $this->filter( + function ($recurrence) use ($after, $inc) { + /** @var $recurrence Recurrence */ + $end = $recurrence->getEnd(); + + if ($inc) { + return $end >= $after; + } + + return $end > $after; + } + ); + } +} |