@@ -93,25 +93,23 @@ public function isValidWeekDay($value, $time)
9393 $ month = \str_pad ($ time [8 ], 2 , '0 ' , \STR_PAD_LEFT );
9494
9595 if (\strpos ($ value , 'L ' )) {
96- return $ this ->lastWeekDay ($ value , $ month , $ time );
96+ return $ this ->isLastWeekDay ($ value , $ month , $ time );
9797 }
9898
99- if (\strpos ($ value , '# ' )) {
100- $ value = \explode ('# ' , \str_replace ('0# ' , '7# ' , $ value ));
99+ if (!\strpos ($ value , '# ' )) {
100+ return null ;
101+ }
101102
102- if ($ value [0 ] < 0 || $ value [0 ] > 7 || $ value [1 ] < 1 || $ value [1 ] > 5 || $ time [9 ] != $ value [0 ]) {
103- return false ;
104- }
103+ list ($ day , $ nth ) = \explode ('# ' , \str_replace ('0# ' , '7# ' , $ value ));
105104
106- return \intval ($ time [7 ] / 7 ) == $ value [1 ] - 1 ;
105+ if (!$ this ->isNthWeekDay ($ day , $ nth ) || $ time [9 ] != $ day ) {
106+ return false ;
107107 }
108108
109- // @codeCoverageIgnoreStart
110- return false ;
111- // @codeCoverageIgnoreEnd
109+ return \intval ($ time [7 ] / 7 ) == $ nth - 1 ;
112110 }
113111
114- protected function lastWeekDay ($ value , $ month , $ time )
112+ protected function isLastWeekDay ($ value , $ month , $ time )
115113 {
116114 $ value = \explode ('L ' , \str_replace ('7L ' , '0L ' , $ value ));
117115 $ decr = $ time [6 ];
@@ -125,4 +123,9 @@ protected function lastWeekDay($value, $month, $time)
125123
126124 return false ;
127125 }
126+
127+ protected function isNthWeekDay ($ day , $ nth )
128+ {
129+ return !($ day < 0 || $ day > 7 || $ nth < 1 || $ nth > 5 );
130+ }
128131}
0 commit comments