/** * # Example: * * This: □□□□□□■■■■■■■■■■■■□□□□□□□□□□□□□□□□□□□□□□□□□□□ * Other: □□□□□□□□□□□□□□□□□□■■■■■■■■■■■□□□□□□□□□□□□□□□□ * * # False examples: * * This: □□□□□□■■■■■■■■■■■■□□□□□□□□□□□□□□□□□□□□□□□□□□□ * Other: □□□□□□□□□□□□□□□□□□□□□□□■■■■■■■■■■■□□□□□□□□□□□ * * This: □□□□□□□□□□□□□□□□□□■■■■■■■■■■■□□□□□□□□□□□□□□□□ * Other: □□□□□□■■■■■■■■■■■■□□□□□□□□□□□□□□□□□□□□□□□□□□□ * * @param DateTimeInterval $other * @param string $precision * @return bool */ public function isFollowedBy(DateTimeInterval $other, string $precision = IntervalUtils::PRECISION_ON_SECOND) : bool { if ($this->getLeft() > $other->getRight()) { // intentionally compares boundaries return FALSE; } /** @var DateTime $modifiedPlus */ $modifiedPlus = $this->getRight()->getValue()->modifyClone("+{$precision}"); /** @var DateTime $modifiedMinus */ $modifiedMinus = $other->getLeft()->getValue()->modifyClone("-{$precision}"); return $modifiedPlus->isGreaterThanOrEqual($other->getLeft()->getValue()) && $modifiedPlus->isLessThanOrEqual($other->getRight()->getValue()) && $modifiedMinus->isLessThanOrEqual($this->getRight()->getValue()) && $modifiedMinus->isGreaterThanOrEqual($this->getLeft()->getValue()); }
/** * @inheritdoc */ public function format(DateTimeInterval $value) { $leftValue = $this->dateTimeConverter->format($value->getLeft()->getValue()); $rightValue = $this->dateTimeConverter->format($value->getRight()->getValue()); return sprintf($this->format, $leftValue, $rightValue); }