v1.1.0+3
This commit is contained in:
@@ -66,9 +66,10 @@ class ScheduleService {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>?> getScheduleByDate(DateTime datetime) async {
|
||||
final datetimeStartWithOffset = datetime.copyWith(hour: 0, minute: 0, second: 0, microsecond: 0, millisecond: 0)
|
||||
.add(dayOffset);
|
||||
Future<List<Map<String, dynamic>>?> getScheduleByDate(DateTime datetime, {bool force = false}) async {
|
||||
final dateStart = datetime.copyWith(hour: 0, minute: 0, second: 0, microsecond: 0, millisecond: 0);
|
||||
final dateEnd = datetime.copyWith(hour: 23, minute: 59, second: 59, microsecond: 999, millisecond: 999);
|
||||
final datetimeStartWithOffset = dateStart.copyWith().add(dayOffset);
|
||||
|
||||
final DateTime usedScheduleDatetime = datetime.isAfter(datetimeStartWithOffset)
|
||||
? datetime
|
||||
@@ -93,23 +94,34 @@ class ScheduleService {
|
||||
for (var i = 0; i < schedule.length; i++) {
|
||||
final scheduleItem = schedule[i];
|
||||
final int duration = (scheduleItem['duration'] as int);
|
||||
final DateTime start = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset));
|
||||
DateTime start = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset));
|
||||
DateTime end = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset + duration));
|
||||
durationOffset += duration;
|
||||
|
||||
bool showEndDate = false;
|
||||
if(i == (schedule.length -1)) {
|
||||
final scheduleNextDay = await getScheduleByDate(datetime.copyWith().add(const Duration(days: 1)));
|
||||
final firstScheduleElement = scheduleNextDay?[0];
|
||||
if(firstScheduleElement != null && (firstScheduleElement['direction'] as String) == (scheduleItem['direction'] as String)) {
|
||||
end = end.add(Duration(minutes: firstScheduleElement['duration'] as int));
|
||||
showEndDate = true;
|
||||
if(!force) {
|
||||
if(i == 0) {
|
||||
final schedulePrevDay = await getScheduleByDate(datetime.copyWith().subtract(const Duration(days: 1)), force: true);
|
||||
final lastScheduleElement = schedulePrevDay?.last;
|
||||
if(lastScheduleElement != null && (lastScheduleElement['direction'] as String) == (scheduleItem['direction'] as String)) {
|
||||
start = start.subtract(Duration(minutes: lastScheduleElement['duration'] as int));
|
||||
}
|
||||
}
|
||||
|
||||
if(i == (schedule.length -1)) {
|
||||
final scheduleNextDay = await getScheduleByDate(datetime.copyWith().add(const Duration(days: 1)), force: true);
|
||||
final firstScheduleElement = scheduleNextDay?.first;
|
||||
if(firstScheduleElement != null && (firstScheduleElement['direction'] as String) == (scheduleItem['direction'] as String)) {
|
||||
end = end.add(Duration(minutes: firstScheduleElement['duration'] as int));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
schedule[i]['start'] = start;
|
||||
schedule[i]['show_start_date'] = !(start.isAfter(dateStart) && start.isBefore(dateEnd));
|
||||
schedule[i]['end'] = end;
|
||||
schedule[i]['show_end_date'] = !(end.isAfter(dateStart) && end.isBefore(dateEnd));
|
||||
}
|
||||
|
||||
return schedule;
|
||||
}
|
||||
|
||||
@@ -118,39 +130,12 @@ class ScheduleService {
|
||||
final List<Map<String, dynamic>>? schedule = await getScheduleByDate(now);
|
||||
if(schedule == null) return null;
|
||||
|
||||
DateTime datetimeStartWithOffset = now.copyWith(hour: 0, minute: 0, second: 0, microsecond: 0, millisecond: 0)
|
||||
.add(dayOffset);
|
||||
|
||||
if(now.isBefore(datetimeStartWithOffset)) {
|
||||
datetimeStartWithOffset = datetimeStartWithOffset.subtract(const Duration(days: 1));
|
||||
}
|
||||
|
||||
int durationOffset = 0;
|
||||
for (var i = 0; i < schedule.length; i++) {
|
||||
final scheduleItem = schedule[i];
|
||||
final int duration = (scheduleItem['duration'] as int);
|
||||
final DateTime start = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset));
|
||||
DateTime end = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset + duration));
|
||||
durationOffset += duration;
|
||||
|
||||
bool showEndDate = false;
|
||||
|
||||
if(i == (schedule.length -1)) {
|
||||
final scheduleNextDay = await getScheduleByDate(now.copyWith().add(const Duration(days: 1)));
|
||||
final firstScheduleElement = scheduleNextDay?[0];
|
||||
if(firstScheduleElement != null && (firstScheduleElement['direction'] as String) == (scheduleItem['direction'] as String)) {
|
||||
end = end.add(Duration(minutes: firstScheduleElement['duration'] as int));
|
||||
showEndDate = true;
|
||||
}
|
||||
}
|
||||
for(var i = 0; i < schedule.length; i++) {
|
||||
final start = schedule[i]['start'];
|
||||
final end = schedule[i]['end'];
|
||||
|
||||
if(now.isAfter(start) && now.isBefore(end)) {
|
||||
return <String, dynamic>{
|
||||
"direction": scheduleItem['direction'] as String,
|
||||
"start": start,
|
||||
"end": end,
|
||||
"need_show_end_date": showEndDate,
|
||||
};
|
||||
return schedule[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user