return $results == $expected; }; $unitTests['Modes'] = function () { $expected = array(array('m' => 500), array('m' => 501), array('m' => 501), array('m' => 500, 'rest' => 31), array('m' => 500 + 31.0 / 60.0)); $tiFloor = new SimpleTimeInterval(array('m' => 500, 's' => 31), 'floor'); $tiRound = new SimpleTimeInterval(array('m' => 500, 's' => 31), 'round'); $tiCeil = new SimpleTimeInterval(array('m' => 500, 's' => 31), 'ceil'); $tiRest = new SimpleTimeInterval(array('m' => 500, 's' => 31), 'rest'); $tiFloat = new SimpleTimeInterval(array('m' => 500, 's' => 31), 'float'); $results = array($tiFloor->to('m'), $tiRound->to('m'), $tiCeil->to('m'), $tiRest->to('m'), $tiFloat->to('m')); 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));