groupByHour method

List<TicketsGroupedByTimeFrame> groupByHour(
  1. DateTime dateStart,
  2. DateTime dateEnd
)

Implementation

List<TicketsGroupedByTimeFrame> groupByHour(
    DateTime dateStart, DateTime dateEnd) {
  final emptyGTickets = List<TicketsGroupedByTimeFrame>.generate(
      24, (index) => TicketsGroupedByTimeFrame(index + 1, {}));
  for (final ticket in this) {
    if (ticket.date.isAfter(dateStart) && ticket.date.isBefore(dateEnd)) {
      if (emptyGTickets
          .any((element) => element.timeFrame == ticket.date.hour)) {
        final i = emptyGTickets
            .indexWhere((element) => element.timeFrame == ticket.date.day);
        emptyGTickets[i].tickets.add(ticket);
      } else {
        throw 'ticket ${ticket.toJson()} date is anormal in daily';
      }
    }
  }
  emptyGTickets.sort((a, b) => a.timeFrame.compareTo(b.timeFrame));
  return emptyGTickets;
}