/** * Attaches a time object to collection * @param \WallaceMaxters\Timer\Time $time * @return \Wallacemaxters\Timer\Collection * */ public function attach(Time $time) { $time->setFormat($this->format); $this->add($time); return $this; }
/** * Get a new instance of WallaceMaxters\Timer\Time of diff with another Time * * @param Time $time time for comparation * @param boolean $absolute * @return \WallaceMaxters\Timer\Time * */ public function diff(Time $time, $absolute = true) { $diff = $this->getSeconds() - $time->getSeconds(); return new self(0, 0, $absolute ? abs($diff) : $diff); }
public function testFormatNegativeSign() { // Positive $time = Time::createFromFormat('%h:%i:%s', '00:50:00'); $this->assertEquals('00:50:00', $time->format('%r%h:%i:%s')); $this->assertEquals('+00:50:00', $time->format('%R%h:%i:%s')); // Negative $time2 = Time::createFromFormat('%R%h:%i:%s', '-02:00:00'); $this->assertEquals('-02:00:00', $time2->format('%R%h:%i:%s')); $this->assertEquals('-02:00:00', $time2->format('%r%h:%i:%s')); // Positive with R $time = Time::createFromFormat('%R%h:%i:%s', '+22:00:00'); $this->assertEquals('+22:00', $time->format('%R%h:%i')); }
public function testRemove() { $time1 = Time::create(0, 20); $c1 = Collection::create([$time1, 30, 40, 50]); $time2 = $c1[3]; $deletes[] = $c1->remove($time1); $deletes[] = $c1->remove($time2); $this->assertEquals([0, 3], $deletes); }