/** * Validate a DateTimeImmutable object. * * @param string|\DateTimeInterface $datetime * * @return \DateTimeImmutable */ protected static function validateDatePoint($datetime) { if ($datetime instanceof DateTimeImmutable) { return $datetime; } if ($datetime instanceof DateTime) { return new DateTimeImmutable($datetime->format(self::DATE_LOCALE), $datetime->getTimeZone()); } return new DateTimeImmutable($datetime); }
public function runsAt(\DateTimeInterface $time) { if ($time->getTimeZone() != $this->tz) { $time = clone $time; $time->setTimeZone($this->tz); } if (!in_array($time->format('i'), $this->minutes)) { return false; } if (!in_array($time->format('H'), $this->hours)) { return false; } if ($this->daysOfMonth != self::LAST_DAY_OF_MONTH && !in_array($time->format('j'), $this->daysOfMonth)) { return false; } if ($this->daysOfMonth == self::LAST_DAY_OF_MONTH && $time->format('j') != $time->format('t')) { return false; } if (!in_array($time->format('w'), $this->daysOfWeek)) { return false; } if (!in_array($time->format('n'), $this->months)) { return false; } return true; }