improved yOfDateTime precision and period-based calculation in workweek calendar
This commit is contained in:
@@ -1169,8 +1169,23 @@ class _PeriodLayout {
|
|||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
double yOfDateTime(DateTime t) =>
|
double yOfDateTime(DateTime t) {
|
||||||
yOf(TimeOfDay(hour: t.hour, minute: t.minute));
|
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
|
/// 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.
|
/// non-break period. Returns null when y is past the last period.
|
||||||
|
|||||||
Reference in New Issue
Block a user