PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 2.9.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v2.9.0
4.9.0 0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / vendor / woocommerce / action-scheduler / lib / cron-expression / CronExpression_DayOfMonthField.php
wp-mail-smtp / vendor / woocommerce / action-scheduler / lib / cron-expression Last commit date
CronExpression.php 5 years ago CronExpression_AbstractField.php 5 years ago CronExpression_DayOfMonthField.php 5 years ago CronExpression_DayOfWeekField.php 5 years ago CronExpression_FieldFactory.php 5 years ago CronExpression_FieldInterface.php 5 years ago CronExpression_HoursField.php 5 years ago CronExpression_MinutesField.php 5 years ago CronExpression_MonthField.php 5 years ago CronExpression_YearField.php 5 years ago LICENSE 5 years ago
CronExpression_DayOfMonthField.php
111 lines
1 <?php
2
3 /**
4 * Day of month field. Allows: * , / - ? L W
5 *
6 * 'L' stands for "last" and specifies the last day of the month.
7 *
8 * The 'W' character is used to specify the weekday (Monday-Friday) nearest the
9 * given day. As an example, if you were to specify "15W" as the value for the
10 * day-of-month field, the meaning is: "the nearest weekday to the 15th of the
11 * month". So if the 15th is a Saturday, the trigger will fire on Friday the
12 * 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If
13 * the 15th is a Tuesday, then it will fire on Tuesday the 15th. However if you
14 * specify "1W" as the value for day-of-month, and the 1st is a Saturday, the
15 * trigger will fire on Monday the 3rd, as it will not 'jump' over the boundary
16 * of a month's days. The 'W' character can only be specified when the
17 * day-of-month is a single day, not a range or list of days.
18 *
19 * @author Michael Dowling <mtdowling@gmail.com>
20 */
21 class CronExpression_DayOfMonthField extends CronExpression_AbstractField
22 {
23 /**
24 * Get the nearest day of the week for a given day in a month
25 *
26 * @param int $currentYear Current year
27 * @param int $currentMonth Current month
28 * @param int $targetDay Target day of the month
29 *
30 * @return DateTime Returns the nearest date
31 */
32 private static function getNearestWeekday($currentYear, $currentMonth, $targetDay)
33 {
34 $tday = str_pad($targetDay, 2, '0', STR_PAD_LEFT);
35 $target = new DateTime("$currentYear-$currentMonth-$tday");
36 $currentWeekday = (int) $target->format('N');
37
38 if ($currentWeekday < 6) {
39 return $target;
40 }
41
42 $lastDayOfMonth = $target->format('t');
43
44 foreach (array(-1, 1, -2, 2) as $i) {
45 $adjusted = $targetDay + $i;
46 if ($adjusted > 0 && $adjusted <= $lastDayOfMonth) {
47 $target->setDate($currentYear, $currentMonth, $adjusted);
48 if ($target->format('N') < 6 && $target->format('m') == $currentMonth) {
49 return $target;
50 }
51 }
52 }
53 }
54
55 /**
56 * {@inheritdoc}
57 */
58 public function isSatisfiedBy(DateTime $date, $value)
59 {
60 // ? states that the field value is to be skipped
61 if ($value == '?') {
62 return true;
63 }
64
65 $fieldValue = $date->format('d');
66
67 // Check to see if this is the last day of the month
68 if ($value == 'L') {
69 return $fieldValue == $date->format('t');
70 }
71
72 // Check to see if this is the nearest weekday to a particular value
73 if (strpos($value, 'W')) {
74 // Parse the target day
75 $targetDay = substr($value, 0, strpos($value, 'W'));
76 // Find out if the current day is the nearest day of the week
77 return $date->format('j') == self::getNearestWeekday(
78 $date->format('Y'),
79 $date->format('m'),
80 $targetDay
81 )->format('j');
82 }
83
84 return $this->isSatisfied($date->format('d'), $value);
85 }
86
87 /**
88 * {@inheritdoc}
89 */
90 public function increment(DateTime $date, $invert = false)
91 {
92 if ($invert) {
93 $date->modify('previous day');
94 $date->setTime(23, 59);
95 } else {
96 $date->modify('next day');
97 $date->setTime(0, 0);
98 }
99
100 return $this;
101 }
102
103 /**
104 * {@inheritdoc}
105 */
106 public function validate($value)
107 {
108 return (bool) preg_match('/[\*,\/\-\?LW0-9A-Za-z]+/', $value);
109 }
110 }
111