/** * A method to test the convertDateRangeToOperationIntervalID() method. */ function testConvertDateRangeToOperationIntervalID() { // Test the first operation interval ID range in the week the test was written, // using a default operation interval of 60 minutes $start = new Date('2004-08-15 00:00:00'); $end = new Date('2004-08-15 00:59:59'); $result = OX_OperationInterval::convertDateRangeToOperationIntervalID($start, $end, 60); $this->assertEqual($result, 0); // Test the same range with a new operation interval of 30 minutes to make // sure that the range is recognised as spanning two operation interval IDs $result = OX_OperationInterval::convertDateRangeToOperationIntervalID($start, $end, 30); $this->assertFalse($result); // Test the second operation interval ID range in the week the test was written, // using an operation interval of 30 minutes, and a non-definative date range $start = new Date('2004-08-15 00:35:00'); $end = new Date('2004-08-15 00:40:00'); $result = OX_OperationInterval::convertDateRangeToOperationIntervalID($start, $end, 30); $this->assertEqual($result, 1); }
/** * A method to check that two Dates represent either the start and end * of an operation interval, if the operation interval is less than an * hour, or the start and end of an hour otherwise. * * @static * @param Date $oStart The interval start date. * @param Date $oEnd The interval end date. * @param integer $operationInterval The operation interval in minutes. * @return bool Returns true if the dates are correct interval * start/end dates, false otherwise. */ function checkIntervalDates($oStart, $oEnd, $operationInterval = 0) { if ($operationInterval < 1) { $operationInterval = OX_OperationInterval::getOperationInterval(); } if ($operationInterval <= 60) { // Must ensure that only one operation interval is being summarised $operationIntervalID = OX_OperationInterval::convertDateRangeToOperationIntervalID($oStart, $oEnd, $operationInterval); if (is_bool($operationIntervalID) && !$operationIntervalID) { return false; } // Now check that the start and end dates match the start and end // of the operation interval $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oStart, $operationInterval); if (!$oStart->equals($aDates['start'])) { return false; } if (!$oEnd->equals($aDates['end'])) { return false; } } else { // Must ensure that only one hour is being summarised if (!OX_OperationInterval::checkDatesInSameHour($oStart, $oEnd)) { return false; } // Now check that the start and end dates are match the start and // end of the hour $oHourStart = new Date(); $oHourStart->copy($oStart); $oHourStart->setMinute('00'); $oHourStart->setSecond('00'); $oHourEnd = new Date(); $oHourEnd->copy($oEnd); $oHourEnd->setMinute('59'); $oHourEnd->setSecond('59'); if (!$oStart->equals($oHourStart)) { return false; } if (!$oEnd->equals($oHourEnd)) { return false; } } return true; }