/** * Get the distance between this and the given month. * * @param Month $month * * @return int Number of months */ public function getDistance(Month $month) { $yd = $this->getYear() - $month->getYear(); $md = $this->getMonth() - $month->getMonth(); return ($yd * 12 + $md) * -1; }
/** * @depends testGetYear */ public function testSubYear() { $month = new Month(new \DateTime('1987-06-18')); $month->subYear(); $this->assertEquals(1986, $month->getYear()); $month->subYear(0); $this->assertEquals(1986, $month->getYear()); $month->subYear(2); $this->assertEquals(1984, $month->getYear()); }