Skip to content

Commit

Permalink
:recycler: Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-jitiya-simform committed Nov 26, 2024
1 parent 70c4a10 commit 2c79913
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/src/modals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ class RecurrenceSettings {
final List<int> weekdays;
final List<DateTime>? excludeDates;

// For recurrence patterns other than weekly, where the event may not repeat
// on the start date.
// Excludes one occurrence since the event is already counted
// for the start date.
int get _occurrences => (occurrences ?? 1) - 1;

/// Calculates the end date for a monthly recurring event
Expand All @@ -157,6 +161,7 @@ class RecurrenceSettings {
/// Example: If the start date is 29-01-25 and the recurrence ends
/// after 2 occurrences,
/// the end date will be 29-03-25 because February does not have a 29th date.
/// Similarly for 30/31 date as well.
DateTime get _endDateMonthly {
var repetition = _occurrences;
var nextDate = startDate;
Expand All @@ -171,7 +176,6 @@ class RecurrenceSettings {
// Adjust the date if the resulting month does not have the same day
// as the start date
// Example: DateTime(2024, 10 + 1, 31) gives 2024-12-01
// TODO(Shubham): Review if in next consecutive month as well date does not found?
if (nextDate.day != startDate.day) {
nextDate = DateTime(
nextDate.year,
Expand Down Expand Up @@ -285,7 +289,7 @@ class RecurrenceSettings {
}
}

/// Calculates the end date for a recurring event based on the specified
/// Returns the end date for a recurring event based on the specified
/// number of occurrences.
///
/// This method requires at least one occurrence to process the recurrence.
Expand Down

0 comments on commit 2c79913

Please sign in to comment.