45 $this->letter = $letter;
56 $this->daysOfMonth = $days;
68 $this->daysOfWeek = $days;
80 $this->monthsOfYear = $months;
98 private function getDateTimeByData(
array $months = [],
array $days = [])
102 for (
$i = 1;
$i <= 12;
$i++)
109 for (
$i = 1;
$i <= 31;
$i++)
114 foreach ([
false,
true] as $nextYear)
116 foreach ($months as $month)
118 foreach ($days as $day)
120 $date = $this->getDateTime($month, $day, $nextYear);
121 if ($this->checkDateTime($date))
132 private function checkDateTime(DateTime $date =
null)
134 static $current =
null;
135 if ($current ===
null)
145 return $current < $date->getTimestamp();
148 private function getDateTime($month =
null, $day =
null, $nextYear =
false)
150 if ($month ===
null && $day ===
null)
152 $date =
new DateTime();
156 $date = DateTime::createFromTimestamp(
157 mktime(0, 0, 0, $month, $day, date(
'Y') + ($nextYear ? 1 : 0))
161 return $date->setTime((
int) $this->hours, (
int) $this->minutes);
172 if (empty($this->daysOfWeek) && empty($this->monthsOfYear) && empty($this->daysOfMonth))
177 if (!empty($this->monthsOfYear) || !empty($this->daysOfMonth))
179 $date = $this->getDateTimeByData($this->monthsOfYear, $this->daysOfMonth);
183 $date = $this->getDateTime();
188 $date->add(
"+1 days");
191 if (!$this->checkDateTime($date))
196 $day = (int) date(
'w', $date->getTimestamp());
197 $day = $day === 0 ? 7 : $day;
198 if (in_array($day, $this->daysOfWeek))
215 $this->letter->set(
'MONTHS_OF_YEAR', implode(
',', $this->monthsOfYear));
216 $this->letter->set(
'DAYS_OF_MONTH', implode(
',', $this->daysOfMonth));
217 $this->letter->set(
'DAYS_OF_WEEK', implode(
',', $this->daysOfWeek));
218 $this->letter->set(
'TIMES_OF_DAY', $this->hours ? ($this->hours .
':' . $this->minutes) :
null);
219 $this->letter->set(
'REITERATE',
'Y');
220 $this->letter->set(
'AUTO_SEND_TIME', $this->
getNextDate());
221 $this->letter->save();
222 $this->letter->getState()->wait($this);
233 $this->letter->set(
'MONTHS_OF_YEAR',
null);
234 $this->letter->set(
'DAYS_OF_MONTH',
null);
235 $this->letter->set(
'DAYS_OF_WEEK',
null);
236 $this->letter->set(
'TIMES_OF_DAY',
null);
237 $this->letter->set(
'REITERATE',
'N');
263 foreach ($days as $day)
266 if (preg_match(
"/^(\d{1,2})$/", $day, $found))
268 if (intval($found[1]) < 1 || intval($found[1]) > 31)
277 elseif (preg_match(
"/^(\d{1,2})-(\d{1,2})$/", $day, $found))
279 if (intval($found[1]) < 1 || intval($found[1]) > 31 || intval($found[2]) < 1 || intval($found[2]) > 31 || intval($found[1]) >= intval($found[2]))
285 for (
$i = intval($found[1]);
$i <= intval($found[2]);
$i++)
320 foreach($days as $day)
325 preg_match(
"/^(\d)$/", $day, $found)
356 foreach($months as $month)
358 $month = trim($month);
361 preg_match(
"/^(\d{1,2})$/", $month, $found)
393 preg_match(
"/^(\d{1,2}):(\d{1,2})$/",
$time, $found)
398 return [$found[1], $found[2]];
414 $timesOfDayHours = [
'00',
'30'];
415 for ($hour = 0; $hour < 24; $hour++)
417 $hourPrint = str_pad($hour, 2,
"0", STR_PAD_LEFT);
418 foreach ($timesOfDayHours as $timePartHour)
420 $list[] = $hourPrint .
":" . $timePartHour;
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)