@@ -87,26 +87,26 @@ public function getNextSchedules(string $fromDateStr = 'now', int $limit = 5): a
8787 $ dates = [];
8888
8989 foreach ($ this ->oneTimeEvents as $ schedule ) {
90- $ dt = new \DateTime ($ fromDateStr );
91- $ dt ->modify ($ schedule );
90+ if ($ schedule == 'now ' ) $ schedule = '+1 second ' ;
91+ $ d = new \DateTime ($ fromDateStr );
92+ $ d ->modify ($ schedule );
9293
93- if ($ this ->isInTimeFrame ($ dt , $ fromDateStr )) {
94- $ dates [$ dt ->format ('YmdHis ' )] = $ dt ;
94+ if ($ this ->isInTimeFrame ($ d , $ fromDateStr )) {
95+ $ dates [$ d ->format ('YmdHis ' )] = clone $ d ;
9596 }
9697 }
9798
9899 foreach ($ this ->schedules as $ schedule ) {
99100 $ d = new \DateTime ($ fromDateStr );
100101
101102 for ($ i =0 , $ maxRecursion = 100 * $ limit ; $ i < $ limit && $ maxRecursion > 0 ; ++$ i , --$ maxRecursion ) {
102-
103103 if ($ this ->isDateRelative ($ schedule )) {
104+ $ d ->modify ($ schedule );
105+
104106 if ($ this ->startTime instanceof \DateTime && $ d < $ this ->startTime ->modify ($ d ->format ('Y-m-d ' ))) {
105107 $ d ->modify ($ this ->startTime ->format ('H:i:s ' ));
106108 } elseif ($ this ->endTime instanceof \DateTime && $ d > $ this ->endTime ->modify ($ d ->format ('Y-m-d ' ))) {
107109 $ d ->modify ('next day ' )->modify ($ this ->startTime ->format ('H:i:s ' ));
108- } else {
109- $ d ->modify ($ schedule );
110110 }
111111
112112 if (!array_key_exists ($ d ->format ('YmdHis ' ), $ dates )) {
@@ -124,6 +124,7 @@ public function getNextSchedules(string $fromDateStr = 'now', int $limit = 5): a
124124 }
125125
126126 $ this ->orderDates ($ dates );
127+
127128 return array_slice ($ dates , 0 , $ limit );
128129 }
129130
@@ -135,7 +136,7 @@ public function getNextSchedules(string $fromDateStr = 'now', int $limit = 5): a
135136 private function orderDates (array &$ dates ): void
136137 {
137138 uasort ($ dates , function ($ a , $ b ) {
138- return strtotime ($ a ->format ('Y-m-d H:i:s ' )) > strtotime ($ b ->format ('Y-m-d H:i:s ' )) ? 1 : - 1 ;
139+ return strtotime ($ a ->format ('Y-m-d H:i:s ' )) - strtotime ($ b ->format ('Y-m-d H:i:s ' ));
139140 });
140141 }
141142
0 commit comments