@@ -209,28 +209,89 @@ public function testOffsetDecrementsPreviousRunDate(): void
209
209
$ this ->assertEquals ($ dtExpected , $ cron ->getPreviousRunDate ($ dtCurrent , 0 , false , $ tz ->getName ()));
210
210
}
211
211
212
- public function testOffsetIncrementsMultipleRunDates (): void
212
+ public static function dayLightSavingExamples (): \ Generator
213
213
{
214
- $ expression = "0 1 * * 0 " ;
215
- $ cron = new CronExpression ($ expression );
216
- $ tz = new \DateTimeZone ("Europe/London " );
214
+ yield 'fixed hour before turnover point ' => [
215
+ "0 1 * * 0 " ,
216
+ [
217
+ "2021-03-14 01:00+00:00 " ,
218
+ "2021-03-21 01:00+00:00 " ,
219
+ "2021-03-28 02:00+01:00 " ,
220
+ "2021-04-04 01:00+01:00 " ,
221
+ "2021-04-11 01:00+01:00 " ,
222
+ ],
223
+ new \DateTimeZone ("Europe/London " ),
224
+ "2021-03-13 00:00+00:00 " ,
225
+ "2021-04-12 00:00+01:00 " ,
226
+ ];
217
227
218
- $ expected = [
219
- $ this ->createDateTimeExactly ("2021-03-14 01:00+00:00 " , $ tz ),
220
- $ this ->createDateTimeExactly ("2021-03-21 01:00+00:00 " , $ tz ),
221
- $ this ->createDateTimeExactly ("2021-03-28 02:00+01:00 " , $ tz ),
222
- $ this ->createDateTimeExactly ("2021-04-04 01:00+01:00 " , $ tz ),
223
- $ this ->createDateTimeExactly ("2021-04-11 01:00+01:00 " , $ tz ),
228
+ yield 'fixed hour after turnover point #202 ' => [
229
+ "0 10 * * * " ,
230
+ [
231
+ "2025-03-08 10:00-06:00 " ,
232
+ "2025-03-09 10:00-05:00 " ,
233
+ "2025-03-10 10:00-05:00 " ,
234
+ ],
235
+ new \DateTimeZone ("America/Chicago " ),
236
+ "2025-03-08 09:00-06:00 " ,
237
+ "2025-03-10 11:00-05:00 " ,
224
238
];
225
239
226
- $ dtCurrent = $ this ->createDateTimeExactly ("2021-03-13 00:00+00:00 " , $ tz );
227
- $ actual = $ cron ->getMultipleRunDates (5 , $ dtCurrent , false , true , $ tz ->getName ());
240
+ yield 'fixed hour after turnover point #154 ' => [
241
+ "30 07 * * * " ,
242
+ [
243
+ "2023-03-11 07:30-05:00 " ,
244
+ "2023-03-12 07:30-04:00 " ,
245
+ "2023-03-13 07:30-04:00 " ,
246
+ ],
247
+ new \DateTimeZone ("America/New_York " ),
248
+ "2023-03-10 08:00-05:00 " ,
249
+ "2023-03-13 08:00-04:00 " ,
250
+ ];
251
+
252
+ yield 'fixed time inside the daylight transition hour ' => [
253
+ "30 2 * * * " ,
254
+ [
255
+ "2025-03-08 02:30-06:00 " ,
256
+ "2025-03-09 03:30-05:00 " ,
257
+ "2025-03-10 02:30-05:00 " ,
258
+ ],
259
+ new \DateTimeZone ("America/Chicago " ),
260
+ "2025-03-08 01:30-06:00 " ,
261
+ "2025-03-10 11:00-05:00 " ,
262
+ ];
263
+ }
264
+
265
+ /**
266
+ * @param string[] $expected
267
+ *
268
+ * @dataProvider dayLightSavingExamples
269
+ */
270
+ public function testOffsetIncrementsMultipleRunDates (
271
+ string $ expression ,
272
+ array $ expected ,
273
+ \DateTimeZone $ tz ,
274
+ string $ currentDate ,
275
+ string $ currentInvertedDate
276
+ ): void {
277
+ $ cron = new CronExpression ($ expression );
278
+
279
+ $ expected = array_map (
280
+ function (string $ dtString ) use ($ tz ) {
281
+ return $ this ->createDateTimeExactly ($ dtString , $ tz );
282
+ },
283
+ $ expected
284
+ );
285
+ $ total = count ($ expected );
286
+
287
+ $ dtCurrent = $ this ->createDateTimeExactly ($ currentDate , $ tz );
288
+ $ actual = $ cron ->getMultipleRunDates ($ total , $ dtCurrent , false , true , $ tz ->getName ());
228
289
foreach ($ expected as $ dtExpected ) {
229
290
$ this ->assertContainsEquals ($ dtExpected , $ actual );
230
291
}
231
292
232
- $ dtCurrent = $ this ->createDateTimeExactly (" 2021-04-12 00:00+01:00 " , $ tz );
233
- $ actual = $ cron ->getMultipleRunDates (5 , $ dtCurrent , true , true , $ tz ->getName ());
293
+ $ dtCurrent = $ this ->createDateTimeExactly ($ currentInvertedDate , $ tz );
294
+ $ actual = $ cron ->getMultipleRunDates ($ total , $ dtCurrent , true , true , $ tz ->getName ());
234
295
foreach ($ expected as $ dtExpected ) {
235
296
$ this ->assertContainsEquals ($ dtExpected , $ actual );
236
297
}
@@ -342,7 +403,6 @@ public function testOffsetDecrementsEveryOtherHour(): void
342
403
$ expected = [
343
404
$ this ->createDateTimeExactly ("2020-10-24 22:00+01:00 " , $ tz ),
344
405
$ this ->createDateTimeExactly ("2020-10-25 00:00+01:00 " , $ tz ),
345
- $ this ->createDateTimeExactly ("2020-10-25 01:00+00:00 " , $ tz ),
346
406
$ this ->createDateTimeExactly ("2020-10-25 02:00+00:00 " , $ tz ),
347
407
$ this ->createDateTimeExactly ("2020-10-25 04:00+00:00 " , $ tz ),
348
408
];
0 commit comments