/** * Check start/end dates - note that check is the reverse of normal check: * if the operation interval is <= 60, must be start/end of an hour, to * make sure we update all the operation intervals in the hour, and if * the operation interval > 60, must be the start/end of an operation * interval, to make sure we update all the hours in the operation interval. * * @static * @param Date $oStartDate * @param Date $oEndDate * @return boolean */ function checkDates($oStartDate, $oEndDate) { $aConf = $GLOBALS['_MAX']['CONF']; $operationInterval = $aConf['maintenance']['operation_interval']; if ($operationInterval <= 60) { // Must ensure that only one hour is being summarised if (!OX_OperationInterval::checkDatesInSameHour($oStartDate, $oEndDate)) { return false; } // Now check that the start and end dates are match the start and // end of the hour $oHourStart = new Date(); $oHourStart->setYear($oStartDate->getYear()); $oHourStart->setMonth($oStartDate->getMonth()); $oHourStart->setDay($oStartDate->getDay()); $oHourStart->setHour($oStartDate->getHour()); $oHourStart->setMinute('00'); $oHourStart->setSecond('00'); $oHourEnd = new Date(); $oHourEnd->setYear($oEndDate->getYear()); $oHourEnd->setMonth($oEndDate->getMonth()); $oHourEnd->setDay($oEndDate->getDay()); $oHourEnd->setHour($oEndDate->getHour()); $oHourEnd->setMinute('59'); $oHourEnd->setSecond('59'); if (!$oStartDate->equals($oHourStart)) { return false; } if (!$oEndDate->equals($oHourEnd)) { return false; } } else { // Must ensure that only one operation interval is being summarised $operationIntervalID = OX_OperationInterval::convertDaySpanToOperationIntervalID($oStartDate, $oEndDate, $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 list($oOperationIntervalStart, $oOperationIntervalEnd) = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oStartDate, $operationInterval); if (!$oStartDate->equals($oOperationIntervalStart)) { return false; } if (!$oEndDate->equals($oOperationIntervalEnd)) { return false; } } return true; }
/** * A method to test the checkDatesInSameHour() method. */ function testCheckDatesInSameHour() { $start = new Date('2004-09-11 19:00:00'); $end = new Date('2004-09-11 19:00:00'); $return = OX_OperationInterval::checkDatesInSameHour($start, $end); $this->assertTrue($return); $start = new Date('2004-09-11 19:59:59'); $end = new Date('2004-09-11 19:59:59'); $return = OX_OperationInterval::checkDatesInSameHour($start, $end); $this->assertTrue($return); $start = new Date('2004-09-11 19:00:00'); $end = new Date('2004-09-11 19:00:01'); $return = OX_OperationInterval::checkDatesInSameHour($start, $end); $this->assertTrue($return); $start = new Date('2004-09-11 19:00:00'); $end = new Date('2004-09-11 19:59:59'); $return = OX_OperationInterval::checkDatesInSameHour($start, $end); $this->assertTrue($return); $start = new Date('2004-09-11 19:59:59'); $end = new Date('2004-09-11 20:00:00'); $return = OX_OperationInterval::checkDatesInSameHour($start, $end); $this->assertFalse($return); $start = new Date('2004-09-11 18:00:00'); $end = new Date('2004-09-12 18:00:00'); $return = OX_OperationInterval::checkDatesInSameHour($start, $end); $this->assertFalse($return); $start = new Date('2004-08-11 18:00:00'); $end = new Date('2004-09-11 18:00:00'); $return = OX_OperationInterval::checkDatesInSameHour($start, $end); $this->assertFalse($return); $start = new Date('2003-09-11 18:00:00'); $end = new Date('2004-09-11 18:00:00'); $return = OX_OperationInterval::checkDatesInSameHour($start, $end); $this->assertFalse($return); }
/** * 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; }