@@ -157,11 +157,7 @@ private function checkHoliday($date = null)
157157 {
158158 $ mixReturn = false ;
159159
160- if (empty ($ date )) {
161- $ today = new \DateTime ();
162- } else {
163- $ today = new \DateTime ($ date );
164- }
160+ $ today = $ this ->convertDate ($ date );
165161
166162 foreach ($ this ->config ->get ('general_holidays ' ) as $ holiday ) {
167163 // clone for start/enddate
@@ -177,20 +173,16 @@ private function checkHoliday($date = null)
177173
178174 // check if there's a modifier for holiday range and if it's before or after the actual holiday
179175 if (isset ($ this ->currentConf ['holiday ' ]['additional ' ])) {
180- // creat interval object for difference to add/subtract
176+ // create interval object for difference to add/subtract
181177 $ intervalDiff = new \DateInterval ('P ' . $ this ->currentConf ['holiday ' ]['additional ' ][1 ] . 'D ' );
182178 switch ($ this ->currentConf ['holiday ' ]['additional ' ][0 ]) {
183179 case 'add ' :
184180 // if days are added, date will be enddate
185- $ holidayEnd ->{$ this ->currentConf ['holiday ' ]['additional ' ][0 ]}(
186- $ intervalDiff
187- );
181+ $ holidayEnd ->{$ this ->currentConf ['holiday ' ]['additional ' ][0 ]}($ intervalDiff );
188182 break ;
189183 case 'sub ' :
190184 // if days are subtracted, date will be startdate
191- $ holidayStart ->{$ this ->currentConf ['holiday ' ]['additional ' ][0 ]}(
192- $ intervalDiff
193- );
185+ $ holidayStart ->{$ this ->currentConf ['holiday ' ]['additional ' ][0 ]}($ intervalDiff );
194186 break ;
195187 }
196188 }
@@ -205,9 +197,7 @@ private function checkHoliday($date = null)
205197 );
206198
207199 // check if current date has passed start but not endtime
208- if ((1 == $ intervalStart ->invert )
209- && (0 == $ intervalEnd ->invert )
210- ) {
200+ if ((1 == $ intervalStart ->invert ) && (0 == $ intervalEnd ->invert )) {
211201 $ this ->holiday = $ holiday ;
212202 $ mixReturn = true ;
213203 break ;
@@ -299,4 +289,21 @@ private function checkTime($intervals = array())
299289
300290 return $ this ->checkIntervals ($ return );
301291 }
292+
293+ /**
294+ * Check date string or object and convert if necessary.
295+ *
296+ * @param mixed $date
297+ * @return \DateTime
298+ */
299+ private function convertDate ($ date )
300+ {
301+ if (empty ($ date )) {
302+ $ today = new \DateTime ();
303+ } else {
304+ $ today = new \DateTime ($ date );
305+ }
306+
307+ return $ today ;
308+ }
302309}
0 commit comments