return $results == $expected; }; $unitTests['Preserve Input Units'] = function () { $expected = array('y' => 0, 'months' => 0, 'week' => 0, 'seconds' => 0); $ti = new SimpleTimeInterval(0); $results = $ti->to('y', 'months', 'week', 'seconds'); return $results == $expected; }; $unitTests['Interval toSingle Seconds'] = function () { $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));