groupByDayOfTheMonth method
Implementation
List<TicketsGroupedByTimeFrame> groupByDayOfTheMonth(
DateTime dateStart, DateTime dateEnd) {
// below full month only, prefer flexibility : 15 days displayed for more accuracy
//final start = dateStart.thisMonthFirstDay(dateStart);
//final end = dateStart.thisMonthLastDay(dateStart);
final daysDiff = dateEnd.difference(dateStart).inDays + 1;
final emptyGTickets = List<TicketsGroupedByTimeFrame>.generate(
daysDiff, (index) => TicketsGroupedByTimeFrame(index + 1, {}));
for (final ticket in this) {
if (ticket.date.year == dateStart.year &&
ticket.date.month == dateStart.month) {
if (emptyGTickets
.any((element) => element.timeFrame == ticket.date.day)) {
final i = emptyGTickets
.indexWhere((element) => element.timeFrame == ticket.date.day);
emptyGTickets[i].tickets.add(ticket);
} else {
throw 'ticket ${ticket.toJson()} date is anormal in monthly';
}
}
}
emptyGTickets.sort((a, b) => a.timeFrame.compareTo(b.timeFrame));
return emptyGTickets;
}