for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace CalendR\Period;
/**
* Represents a year.
*
* @author Yohan Giarelli <[email protected]>
*/
class Year extends PeriodAbstract implements \Iterator
{
* @var PeriodInterface
private $current;
* Returns the period as a DatePeriod.
* @return \DatePeriod
public function getDatePeriod()
return new \DatePeriod($this->begin, new \DateInterval('P1D'), $this->end);
}
* @param \DateTime $start
* @return bool
public static function isValid(\DateTime $start)
return $start->format('d-m H:i:s') === '01-01 00:00:00';
* {@inheritdoc}
public function current()
return $this->current;
public function next()
if (null === $this->current) {
$this->current = $this->getFactory()->createMonth($this->begin);
} else {
$this->current = $this->current->getNext();
if (!$this->contains($this->current->getBegin())) {
$this->current = null;
public function key()
return $this->current->getBegin()->format('m');
public function valid()
return null !== $this->current;
public function rewind()
$this->next();
* Returns the year.
* @return string
public function __toString()
return $this->format('Y');
* Returns a \DateInterval equivalent to the period.
* @return \DateInterval
public static function getDateInterval()
return new \DateInterval('P1Y');