Skip to content

Commit

Permalink
Merge pull request #67 from DrBu7cher/fix-divide-by-zero-with-setpos
Browse files Browse the repository at this point in the history
fix(iteration): prevent IntegerDivisionByZeroException with SETPOS
  • Loading branch information
JonasWanke authored Jan 28, 2024
2 parents e14a62c + e8fb5fa commit 1a33b23
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/src/iteration/set_positions_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Iterable<DateTime> buildSetPositionsList(
if (dateSet.isIncluded[k]) dateIndices.add(k);
}

if (dateIndices.isEmpty) continue;

final dateIndex = dateIndices[datePosition % dateIndices.length];
final date = dateSet.firstDayOfYear.add(dateIndex.days);
yield date + timeList[timePosition];
Expand Down
26 changes: 26 additions & 0 deletions test/recurrence_rule_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,32 @@ void main() {
expect(instances.length, 4);
},
);
test('#44: prevent IntegerDivisionByZeroException with SETPOS', () {
final rrule = RecurrenceRule(
frequency: Frequency.monthly,
interval: 1,
byWeekDays: [
ByWeekDayEntry(DateTime.wednesday),
ByWeekDayEntry(DateTime.saturday),
],
byMonths: const [10, 12],
bySetPositions: const [2, 4],
until: DateTime.utc(2023, 01, 06, 14, 15),
);
final start = DateTime.utc(2022);

final instances = rrule.getInstances(start: start).take(5);

expect(
instances,
equals([
DateTime.utc(2022, 10, 05),
DateTime.utc(2022, 10, 12),
DateTime.utc(2022, 12, 07),
DateTime.utc(2022, 12, 14),
]),
);
});
test(
'#46: Start DateTime with microseconds should not skip first instance',
() {
Expand Down

0 comments on commit 1a33b23

Please sign in to comment.