class DateRange in Recurring Dates Field 3.1.x
Same name and namespace in other branches
- 8.2 src/DateRange.php \Drupal\date_recur\DateRange
- 3.x src/DateRange.php \Drupal\date_recur\DateRange
- 3.0.x src/DateRange.php \Drupal\date_recur\DateRange
Defines a date range.
Hierarchy
- class \Drupal\date_recur\DateRange
Expanded class hierarchy of DateRange
5 files declare their use of DateRange
- DateRecurBasicFormatter.php in src/
Plugin/ Field/ FieldFormatter/ DateRecurBasicFormatter.php - DateRecurDateRangeUnitTest.php in tests/
src/ Unit/ DateRecurDateRangeUnitTest.php - DateRecurFieldItemListTest.php in tests/
src/ Kernel/ DateRecurFieldItemListTest.php - DateRecurRruleUnitTest.php in tests/
src/ Unit/ DateRecurRruleUnitTest.php - RlHelper.php in src/
Rl/ RlHelper.php
File
- src/
DateRange.php, line 10
Namespace
Drupal\date_recurView source
class DateRange {
/**
* The start date.
*
* @var \DateTimeInterface
*/
protected $start;
/**
* The end date.
*
* @var \DateTimeInterface
*/
protected $end;
/**
* Creates a new DateRange.
*
* @param \DateTimeInterface $start
* The start date.
* @param \DateTimeInterface $end
* The end date.
*/
public function __construct(\DateTimeInterface $start, \DateTimeInterface $end) {
$this->start = clone $start;
$this->end = clone $end;
$this
->validateDates();
}
/**
* Get the start date.
*
* @return \DateTimeInterface
* The start date.
*/
public function getStart() : \DateTimeInterface {
return clone $this->start;
}
/**
* Set the start date.
*
* @param \DateTimeInterface $start
* The start date.
*
* @return $this
* Return object for chaining.
*
* @throws \InvalidArgumentException
* When there is a problem with the start and/or end date.
*/
public function setStart(\DateTimeInterface $start) {
// Clone to ensure references are lost.
$this->start = clone $start;
$this
->validateDates();
return $this;
}
/**
* Get the end date.
*
* @return \DateTimeInterface
* The end date.
*/
public function getEnd() : \DateTimeInterface {
return clone $this->end;
}
/**
* Set the end date.
*
* @param \DateTimeInterface $end
* The end date.
*
* @return $this
* Return object for chaining.
*
* @throws \InvalidArgumentException
* When there is a problem with the start and/or end date.
*/
public function setEnd(\DateTimeInterface $end) {
// Clone to ensure references are lost.
$this->end = clone $end;
$this
->validateDates();
return $this;
}
/**
* Validates the start and end dates.
*
* @throws \InvalidArgumentException
* When there is a problem with the start and/or end date.
*/
protected function validateDates() : void {
// Normalize end date timezone.
if ($this->start
->getTimezone()
->getName() !== $this->end
->getTimezone()
->getName()) {
throw new \InvalidArgumentException('Provided dates must be the same timezone.');
}
if ($this->end < $this->start) {
throw new \InvalidArgumentException('End date must not occur before start date.');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DateRange:: |
protected | property | The end date. | |
DateRange:: |
protected | property | The start date. | |
DateRange:: |
public | function | Get the end date. | |
DateRange:: |
public | function | Get the start date. | |
DateRange:: |
public | function | Set the end date. | |
DateRange:: |
public | function | Set the start date. | |
DateRange:: |
protected | function | Validates the start and end dates. | |
DateRange:: |
public | function | Creates a new DateRange. |