Skip to content

Commit

Permalink
🔨 Fix monthly recurring event for given occurrences
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-jitiya-simform committed Nov 22, 2024
1 parent 00e7faa commit ebf2875
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions lib/src/modals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,29 @@ class RecurrenceSettings {
final List<int> weekdays;
final List<DateTime>? excludeDates;

/// Calculates the end date for a monthly recurring event
/// based on the start date and occurrences.
DateTime get _endDateMonthly {
final occurrences = interval ?? 1;
return DateTime(
startDate.year,
startDate.month + (occurrences - 1),
startDate.day,
);
int occurrences = (interval ?? 1) - 1;
DateTime nextDate = startDate;

while (occurrences > 0) {
nextDate = DateTime(
nextDate.year,
nextDate.month + 1,
nextDate.day,
);
if (nextDate.day != startDate.day) {
// Update date
nextDate = DateTime(
nextDate.year,
nextDate.month,
startDate.day,
);
}
occurrences--;
}
return nextDate;
}

/// Returns the calculated end date for the selected weekdays and occurrences,
Expand Down

0 comments on commit ebf2875

Please sign in to comment.