24
24
import org .junit .Test ;
25
25
26
26
import java .util .TimeZone ;
27
+ import java .util .concurrent .TimeUnit ;
27
28
28
29
import static java .util .Arrays .asList ;
29
30
import static org .dmfs .jems .hamcrest .matchers .GeneratableMatcher .startsWith ;
@@ -276,4 +277,82 @@ public void testMultipleRulesWithFastForward() throws InvalidRecurrenceRuleExcep
276
277
new DateTime (DateTime .UTC , 2019 , 1 , 3 , 2 , 0 , 0 ).getTimestamp ()
277
278
));
278
279
}
280
+
281
+
282
+ /**
283
+ * See https://github.com/dmfs/lib-recur/issues/85
284
+ * <p>
285
+ * Fast forward to the start date (i.e. not fast forwarding at all)
286
+ */
287
+ @ Test
288
+ public void testFastForwardToStart () throws InvalidRecurrenceRuleException
289
+ {
290
+ DateTime start = new DateTime (DateTime .UTC , 2019 , 1 , 1 , 0 , 0 , 0 );
291
+
292
+ RecurrenceSet ruleSet = new RecurrenceSet ();
293
+ ruleSet .addInstances (new RecurrenceRuleAdapter (new RecurrenceRule ("FREQ=DAILY;INTERVAL=1" )));
294
+
295
+ // Create an iterator using the RecurrenceSet
296
+ RecurrenceSetIterator it = ruleSet .iterator (start .getTimeZone (), start .getTimestamp ());
297
+
298
+ // "Fast forward" to start.
299
+ it .fastForward (start .getTimestamp ());
300
+
301
+ assertThat (() -> it ::next , startsWith (
302
+ new DateTime (DateTime .UTC , 2019 , 1 , 1 , 0 , 0 , 0 ).getTimestamp (),
303
+ new DateTime (DateTime .UTC , 2019 , 1 , 2 , 0 , 0 , 0 ).getTimestamp (),
304
+ new DateTime (DateTime .UTC , 2019 , 1 , 3 , 0 , 0 , 0 ).getTimestamp (),
305
+ new DateTime (DateTime .UTC , 2019 , 1 , 4 , 0 , 0 , 0 ).getTimestamp (),
306
+ new DateTime (DateTime .UTC , 2019 , 1 , 5 , 0 , 0 , 0 ).getTimestamp ()
307
+ ));
308
+ }
309
+
310
+
311
+ @ Test
312
+ public void testFastForwardToPast () throws InvalidRecurrenceRuleException
313
+ {
314
+ DateTime start = new DateTime (DateTime .UTC , 2019 , 1 , 1 , 0 , 0 , 0 );
315
+
316
+ RecurrenceSet ruleSet = new RecurrenceSet ();
317
+ ruleSet .addInstances (new RecurrenceRuleAdapter (new RecurrenceRule ("FREQ=DAILY;INTERVAL=1" )));
318
+
319
+ // Create an iterator using the RecurrenceSet
320
+ RecurrenceSetIterator it = ruleSet .iterator (start .getTimeZone (), start .getTimestamp ());
321
+
322
+ // "Fast forward" to 100 days in the past.
323
+ it .fastForward (start .getTimestamp () - TimeUnit .DAYS .toMillis (100 ));
324
+
325
+ assertThat (() -> it ::next , startsWith (
326
+ new DateTime (DateTime .UTC , 2019 , 1 , 1 , 0 , 0 , 0 ).getTimestamp (),
327
+ new DateTime (DateTime .UTC , 2019 , 1 , 2 , 0 , 0 , 0 ).getTimestamp (),
328
+ new DateTime (DateTime .UTC , 2019 , 1 , 3 , 0 , 0 , 0 ).getTimestamp (),
329
+ new DateTime (DateTime .UTC , 2019 , 1 , 4 , 0 , 0 , 0 ).getTimestamp (),
330
+ new DateTime (DateTime .UTC , 2019 , 1 , 5 , 0 , 0 , 0 ).getTimestamp ()
331
+ ));
332
+ }
333
+
334
+
335
+ @ Test
336
+ public void testFastForwardToNext () throws InvalidRecurrenceRuleException
337
+ {
338
+ DateTime start = new DateTime (DateTime .UTC , 2019 , 1 , 1 , 0 , 0 , 0 );
339
+
340
+ RecurrenceSet ruleSet = new RecurrenceSet ();
341
+ ruleSet .addInstances (new RecurrenceRuleAdapter (new RecurrenceRule ("FREQ=DAILY;INTERVAL=1" )));
342
+
343
+ // Create an iterator using the RecurrenceSet
344
+ RecurrenceSetIterator it = ruleSet .iterator (start .getTimeZone (), start .getTimestamp ());
345
+
346
+ // "Fast forward" to 1 millisecond after start (skipping the first instance only)
347
+ it .fastForward (start .getTimestamp () + 1 );
348
+
349
+ assertThat (() -> it ::next , startsWith (
350
+ new DateTime (DateTime .UTC , 2019 , 1 , 2 , 0 , 0 , 0 ).getTimestamp (),
351
+ new DateTime (DateTime .UTC , 2019 , 1 , 3 , 0 , 0 , 0 ).getTimestamp (),
352
+ new DateTime (DateTime .UTC , 2019 , 1 , 4 , 0 , 0 , 0 ).getTimestamp (),
353
+ new DateTime (DateTime .UTC , 2019 , 1 , 5 , 0 , 0 , 0 ).getTimestamp (),
354
+ new DateTime (DateTime .UTC , 2019 , 1 , 6 , 0 , 0 , 0 ).getTimestamp ()
355
+ ));
356
+ }
357
+
279
358
}
0 commit comments