From c32e64fe74b1e60df921340df3bf7c0c2880f650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20M=C3=BCller?= Date: Thu, 7 May 2026 09:51:13 +0200 Subject: [PATCH] improved yOfDateTime precision and period-based calculation in workweek calendar --- .../widgets/custom_workweek_calendar.dart | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/view/pages/timetable/widgets/custom_workweek_calendar.dart b/lib/view/pages/timetable/widgets/custom_workweek_calendar.dart index 9c776ef..8bfdbd5 100644 --- a/lib/view/pages/timetable/widgets/custom_workweek_calendar.dart +++ b/lib/view/pages/timetable/widgets/custom_workweek_calendar.dart @@ -1169,8 +1169,23 @@ class _PeriodLayout { return y; } - double yOfDateTime(DateTime t) => - yOf(TimeOfDay(hour: t.hour, minute: t.minute)); + double yOfDateTime(DateTime t) { + final tMin = t.hour * 60 + t.minute + t.second / 60.0; + var y = 0.0; + for (final p in periods) { + final pStart = p.start.hour * 60 + p.start.minute; + final pEnd = p.end.hour * 60 + p.end.minute; + final h = _h(p); + if (tMin < pStart) return y; + if (tMin <= pEnd) { + final span = pEnd - pStart; + final ratio = span > 0 ? (tMin - pStart) / span : 0.0; + return y + ratio * h; + } + y += h; + } + return y; + } /// Period at a given y-offset. If y falls into a break, returns the next /// non-break period. Returns null when y is past the last period.