schedules 0.0.5 copy "schedules: ^0.0.5" to clipboard
schedules: ^0.0.5 copied to clipboard

A powerful and flexible Dart package for managing recurring events.

example/main.dart

import 'package:schedules/schedules.dart';

void main() {
  // Create a schedule for your event
  // e.g. Payday every 2 weeks on Friday, beginning on the first Friday
  // after January 1, 2023
  final schedule = Weekly(
    startDate: DateTime(2023, 01, 01),
    frequency: 2,
    weekdays: [DateTime.friday],
  );

  // Get the next 5 dates for your event
  final dates = findNextNOccurrences(schedule, 5);
  print(dates);
}

List<DateTime> findNextNOccurrences(Schedule schedule, int n) {
  final dates = <DateTime>[];
  var currentDate = DateTime.now();

  while (dates.length < n) {
    // Here is the magic: Check if our Schedule occurs on the given date
    // using the "occursOn" method.
    //
    // If the current date fits the Schedule's pattern, add it to our list.
    if (schedule.occursOn(currentDate)) {
      dates.add(currentDate);
    }

    currentDate = currentDate.add(const Duration(days: 1));
  }

  return dates;
}
8
likes
140
pub points
26%
popularity

Publisher

verified publisherandyhorn.dev

A powerful and flexible Dart package for managing recurring events.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on schedules