generateDateList method

List<Map<DateTime, bool>> generateDateList(
  1. int startMillis,
  2. int endMillis,
  3. List<AttendanceLogModel> completedLogs,
  4. bool isSingleSession,
)

Implementation

List<Map<DateTime, bool>> generateDateList(
  int startMillis,
  int endMillis,
  List<AttendanceLogModel> completedLogs,
  bool isSingleSession,
) {
  List<Map<DateTime, bool>> dateList = [];

  // Convert milliseconds to DateTime objects
  DateTime startDate = DateTime.fromMillisecondsSinceEpoch(startMillis);
  DateTime endDate = DateTime.fromMillisecondsSinceEpoch(endMillis);

  // Calculate the number of days between start and end dates
  final daysDifference = endDate.difference(startDate).inDays;

  // Generate date list directly based on the number of days
  for (int i = 0; i <= daysDifference; i++) {
    DateTime currentDate = startDate.add(Duration(days: i));
    bool hasMorningLog = hasLogWithType(completedLogs, currentDate, "ENTRY");
    bool hasEveningLog = hasLogWithType(completedLogs, currentDate, "EXIT");
    dateList.add({
      currentDate:
          isSingleSession ? hasMorningLog : hasMorningLog && hasEveningLog,
    });
  }

  return dateList;
}