simplified code across the app and consolidated duplicated helpers
This commit is contained in:
@@ -29,7 +29,7 @@ bool isOutsideSchoolHours(Appointment a) {
|
||||
}
|
||||
|
||||
int dayIndex(DateTime t, DateTime weekStart) =>
|
||||
DateTime(t.year, t.month, t.day).difference(weekStart).inDays;
|
||||
t.dateOnly.difference(weekStart).inDays;
|
||||
|
||||
class BoundRegion {
|
||||
final TimeRegion region;
|
||||
@@ -41,7 +41,7 @@ class BoundRegion {
|
||||
|
||||
List<BoundRegion> expandRegionsForDay(List<TimeRegion> regions, DateTime day) {
|
||||
final result = <BoundRegion>[];
|
||||
final dayStart = DateTime(day.year, day.month, day.day);
|
||||
final dayStart = day.dateOnly;
|
||||
for (final region in regions) {
|
||||
final isRecurringDaily =
|
||||
region.recurrenceRule != null &&
|
||||
@@ -123,11 +123,7 @@ partitionAppointmentsForWeek(
|
||||
)) {
|
||||
continue;
|
||||
}
|
||||
final idx = DateTime(
|
||||
occLocal.year,
|
||||
occLocal.month,
|
||||
occLocal.day,
|
||||
).difference(weekStart).inDays;
|
||||
final idx = dayIndex(occLocal, weekStart);
|
||||
if (idx < 0 || idx >= 5) continue;
|
||||
final newStart = DateTime(
|
||||
occLocal.year,
|
||||
|
||||
@@ -5,6 +5,7 @@ import '../../../../api/marianumconnect/models/mc_holiday.dart';
|
||||
import '../../../../api/marianumconnect/queries/timetable_get_subjects/timetable_get_subjects_response.dart';
|
||||
import '../../../../api/marianumconnect/queries/timetable_get_week/timetable_get_week_response.dart';
|
||||
import '../../../../api/mhsl/custom_timetable_event/custom_timetable_event.dart';
|
||||
import '../../../../extensions/date_time.dart';
|
||||
import '../../../../storage/timetable_settings.dart';
|
||||
import 'arbitrary_appointment.dart';
|
||||
import 'lesson_color.dart';
|
||||
@@ -150,16 +151,8 @@ class TimetableAppointmentFactory {
|
||||
List<DateTime> _holidayExceptionDates(CustomTimetableEvent event) {
|
||||
final result = <DateTime>[];
|
||||
for (final holiday in holidays) {
|
||||
var day = DateTime(
|
||||
holiday.startDate.year,
|
||||
holiday.startDate.month,
|
||||
holiday.startDate.day,
|
||||
);
|
||||
final last = DateTime(
|
||||
holiday.endDate.year,
|
||||
holiday.endDate.month,
|
||||
holiday.endDate.day,
|
||||
);
|
||||
var day = holiday.startDate.dateOnly;
|
||||
final last = holiday.endDate.dateOnly;
|
||||
while (!day.isAfter(last)) {
|
||||
result.add(
|
||||
DateTime(
|
||||
@@ -171,7 +164,7 @@ class TimetableAppointmentFactory {
|
||||
event.startDate.second,
|
||||
),
|
||||
);
|
||||
day = DateTime(day.year, day.month, day.day + 1);
|
||||
day = day.addDays(1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user