/** * Check with the business rules that the existing downtime's dates * allow editing of the downtime. * @link https://wiki.egi.eu/wiki/GOCDB/Input_System_User_Documentation#Downtime_shortening_and_extension downtime shortening and extension * @param \Downtime $dt * @throws \Exception if the downtime is not eligible for editing. */ public function editValidationDatePreConditions(\Downtime $dt) { $nowUtc = new \DateTime(null, new \DateTimeZone('UTC')); $oldStart = $dt->getStartDate(); $oldEnd = $dt->getEndDate(); // Can't change a downtime if it's already ended if ($oldEnd < $nowUtc) { throw new \Exception("Can't edit a downtime that has already finished."); } $oneDay = \DateInterval::createFromDateString('1 days'); $tomorrowUtc = $nowUtc->add($oneDay); if ($dt->getClassification() == "SCHEDULED") { // Can't edit dt if it start within 24 hours if ($oldStart < $tomorrowUtc) { throw new \Exception("Can't edit a SCHEDULED downtime starting within 24 hours."); } } }