31 $value = str_ireplace(
32 array(
'SUN',
'MON',
'TUE',
'WED',
'THU',
'FRI',
'SAT'),
37 $currentYear = $date->format(
'Y');
38 $currentMonth = $date->format(
'm');
39 $lastDayOfMonth = $date->format(
't');
42 if (strpos($value,
'L')) {
43 $weekday = str_replace(
'7',
'0', substr($value, 0, strpos($value,
'L')));
45 $tdate->setDate($currentYear, $currentMonth, $lastDayOfMonth);
46 while ($tdate->format(
'w') != $weekday) {
47 $tdate->setDate($currentYear, $currentMonth, --$lastDayOfMonth);
50 return $date->format(
'j') == $lastDayOfMonth;
54 if (strpos($value,
'#')) {
55 list($weekday, $nth) = explode(
'#', $value);
57 if ($weekday < 1 || $weekday > 5) {
58 throw new InvalidArgumentException(
"Weekday must be a value between 1 and 5. {$weekday} given");
61 throw new InvalidArgumentException(
'There are never more than 5 of a given weekday in a month');
64 if ($date->format(
'N') != $weekday) {
69 $tdate->setDate($currentYear, $currentMonth, 1);
72 while ($currentDay < $lastDayOfMonth + 1) {
73 if ($tdate->format(
'N') == $weekday) {
74 if (++$dayCount >= $nth) {
78 $tdate->setDate($currentYear, $currentMonth, ++$currentDay);
81 return $date->format(
'j') == $currentDay;
85 if (strpos($value,
'-')) {
86 $parts = explode(
'-', $value);
87 if ($parts[0] ==
'7') {
89 } elseif ($parts[1] ==
'0') {
92 $value = implode(
'-', $parts);
96 $format = in_array(7, str_split($value)) ?
'N' :
'w';
97 $fieldValue = $date->format($format);
105 public function increment(DateTime $date, $invert =
false)
108 $date->sub(
new DateInterval(
'P1D'));
109 $date->setTime(23, 59, 0);
111 $date->add(
new DateInterval(
'P1D'));
112 $date->setTime(0, 0, 0);
123 return (
bool) preg_match(
'/[\*,\/\-0-9A-Z]+/', $value);