Skip to content

Commit

Permalink
Fix instance calculation with after and interval
Browse files Browse the repository at this point in the history
Closes: #71
  • Loading branch information
JonasWanke committed Feb 7, 2024
1 parent 28b09bc commit 902b071
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/src/iteration/iteration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ Iterable<DateTime> getRecurrenceRuleInstances(
var count = rrule.count;

var currentStart = start;

if (count == null && after != null) {
if (rrule.actualInterval == 1 && count == null && after != null) {
// Shortcut for not calculating unnecessary recurrences.
currentStart = after;
}
Expand Down
13 changes: 13 additions & 0 deletions test/recurrence_rule_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,17 @@ void main() {
]),
);
});
test("#71: Counting of interval starts from 'after', not from 'start'", () {
final rule =
RecurrenceRule.fromString('RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=SU');
final start = DateTime.utc(2024, 2, 7);
expect(
rule.getInstances(start: start).take(2),
equals([DateTime.utc(2024, 2, 11), DateTime.utc(2024, 2, 25)]),
);
expect(
rule.getInstances(start: start, after: DateTime.utc(2024, 2, 12)).take(2),
equals([DateTime.utc(2024, 2, 25), DateTime.utc(2024, 3, 10)]),
);
});
}

0 comments on commit 902b071

Please sign in to comment.