generateTimeIntervals function
Implementation
List<DateTime> generateTimeIntervals(DateTime selectedDate) {
final List<DateTime> intervals = [];
final now = DateTime.now();
if (selectedDate.year == now.year &&
selectedDate.month == now.month &&
selectedDate.day == now.day) {
final start = DateTime(
now.year,
now.month,
now.day,
now.hour,
(now.minute ~/ 15 + 1) * 15,
);
for (int j = 0; j < 96; j++) {
final time = start.add(Duration(minutes: j * 15));
if (time.day == selectedDate.day) {
if (j == 0 && time.difference(now).inMinutes <= 5) {
// Skip the first index if the difference is less than or equal to 5 minutes
continue;
}
intervals.add(time);
}
}
} else {
final start =
DateTime(selectedDate.year, selectedDate.month, selectedDate.day);
for (int j = 0; j < 96; j++) {
final time = start.add(Duration(minutes: j * 15));
intervals.add(time);
}
}
return intervals;
}