$expected = array(18271, 18271, 18271, 18271, 18271.0); $tiFloor = new SimpleTimeInterval(array('h' => 5, 'm' => 4, 's' => 31), 'floor'); $tiRound = new SimpleTimeInterval(array('h' => 5, 'm' => 4, 's' => 31), 'round'); $tiCeil = new SimpleTimeInterval(array('h' => 5, 'm' => 4, 's' => 31), 'ceil'); $tiRest = new SimpleTimeInterval(array('h' => 5, 'm' => 4, 's' => 31), 'rest'); $tiFloat = new SimpleTimeInterval(array('h' => 5, 'm' => 4, 's' => 31), 'float'); $results = array($tiFloor->toSingle('s'), $tiRound->toSingle('s'), $tiCeil->toSingle('s'), $tiRest->toSingle('s'), $tiFloat->toSingle('s')); return $results == $expected; }; $unitTests['Interval toNatural'] = function () { $expected = array(array('hours' => 5, 'minutes' => 4, 'seconds' => 1), array('days' => 1, 'minutes' => 4, 'seconds' => 31), array('seconds' => 0), array('hours' => 0)); $ti1 = new SimpleTimeInterval(array('h' => 5, 'm' => 4, 's' => 1)); $ti2 = new SimpleTimeInterval(array('h' => 24, 'm' => 4, 's' => 31)); $ti3 = new SimpleTimeInterval(0); $ti4 = new SimpleTimeInterval(0); $results = array($ti1->toNatural(), $ti2->toNatural(), $ti3->toNatural(), $ti4->toNatural('long', 'h')); return $results == $expected; }; $unitTests['Greatest Exact Unit'] = function () { $expected = array('s', 'm', 'h', 'd', 'w', 'M', 'y', 'days', 'years', 'years'); $tiS = new SimpleTimeInterval(array('s' => 5)); $tiMin = new SimpleTimeInterval(array('m' => 5)); $tiH = new SimpleTimeInterval(array('h' => 5)); $tiD = new SimpleTimeInterval(array('d' => 5)); $tiW = new SimpleTimeInterval(array('w' => 5)); $tiM = new SimpleTimeInterval(array('M' => 5)); $tiY = new SimpleTimeInterval(array('y' => 5)); $tiCase1 = new SimpleTimeInterval(259200); $tiCase2 = new SimpleTimeInterval(array('y' => 1)); $tiCase3 = new SimpleTimeInterval(array('y' => 5)); $results = array($tiS->greatestExactUnit('short'), $tiMin->greatestExactUnit('short'), $tiH->greatestExactUnit('short'), $tiD->greatestExactUnit('short'), $tiW->greatestExactUnit('short'), $tiM->greatestExactUnit('short'), $tiY->greatestExactUnit('short'), $tiCase1->greatestExactUnit('long'), $tiCase2->greatestExactUnit('long'), $tiCase3->greatestExactUnit('long'));