1 | <?php |
||
18 | trait SkipWhenTrait |
||
19 | { |
||
20 | protected $skipWhen = []; |
||
21 | protected $isImported = false; |
||
22 | |||
23 | /** |
||
24 | * @param callable $filter takes a DateTimeInterface, returns true if that date |
||
25 | * is not a business day (and should be skipped) and false if it is |
||
26 | * @param string $filter_name a way to refer to the filter; for future use |
||
27 | * @return $this |
||
28 | */ |
||
29 | 20 | public function skipWhen($filter, $filter_name) |
|
38 | |||
39 | /** |
||
40 | * Convenience method for adding a filter that marks Saturday and Sunday as |
||
41 | * non-business days. |
||
42 | * |
||
43 | * @return $this |
||
44 | */ |
||
45 | 18 | public function skipWhenWeekend() |
|
50 | |||
51 | /** |
||
52 | * Convenience method for adding a filter that marks a certain day/month as |
||
53 | * a non-business day. |
||
54 | * |
||
55 | * @param int $month |
||
56 | * @param int $day |
||
57 | * @param null|string $name optional filter name rather than default of md_$month_$day |
||
58 | * @return $this |
||
59 | */ |
||
60 | 18 | public function skipWhenMonthAndDay($month, $day, $name = null) |
|
61 | { |
||
62 | 18 | $this->skipWhen[$name ?: 'md_' . $month . '_' . $day] = |
|
63 | 18 | FilterFactory::monthAndDay($month, $day); |
|
64 | 18 | return $this; |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * Convenience method for adding a filter that marks the Nth (e.g. 4th) weekday |
||
69 | * (e.g. Thursday, as an integer e.g. 4) of a given month (as an integer) as |
||
70 | * a non-business day. |
||
71 | * |
||
72 | * @param int $n |
||
73 | * @param int $day_of_week |
||
74 | * @param int $month |
||
75 | * @param null|string $name optional filter name rather than default of ndm_$n_$day_of_week_$month |
||
76 | * @return $this |
||
77 | */ |
||
78 | 18 | public function skipWhenNthDayOfWeekOfMonth($n, $day_of_week, $month, $name = null) |
|
84 | |||
85 | /** |
||
86 | * Returns an associative array of filters added via skipWhen() |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | 2 | public function getSkipWhenFilters() |
|
94 | |||
95 | /** |
||
96 | * Replace all skip-when filters with the supplied set |
||
97 | * |
||
98 | * @param array $filters |
||
99 | * @return $this |
||
100 | */ |
||
101 | 22 | protected function replaceSkipWhen(array $filters = []) |
|
106 | |||
107 | /** |
||
108 | * Returns the name of the first "skip when" filter that matches the |
||
109 | * supplied date, or false if none match (i.e. $dt is a business day). |
||
110 | * |
||
111 | * @param DateTime $dt |
||
112 | * @return false|string |
||
113 | */ |
||
114 | 20 | protected function getSkippedBy(DateTime $dt) |
|
124 | } |
||
125 |