improved yOfDateTime precision and period-based calculation in workweek calendar

This commit is contained in:
2026-05-07 09:51:13 +02:00
parent 710e88d744
commit c32e64fe74
@@ -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.