Fill the task calendar's working days in order instead of evenly

A task's estimate now takes each working day of its planned period up to
the assignee's free capacity before the next day gets anything, so 9 h
is booked as 7.5 h + 1.5 h rather than 4.5 h + 4.5 h. What does not fit
in the period still moves past its end and makes the task end later.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-25 12:10:43 +02:00
co-authored by Claude Sonnet 5.5
parent ede7043765
commit eb9346d31c
6 changed files with 23 additions and 45 deletions
@@ -11,19 +11,16 @@ use DateTimeImmutable;
/**
* Books a task's estimated time from its assignee's days (spec 18.3).
*
* The estimate is split evenly over the working days of the planned
* period (not Saturdays, Sundays or holidays); a period of only such days
* splits it over all its days. No day gets more than the assignee's free
* capacity (the daily maximum minus what other open tasks already book):
* what does not fit moves to the next day of the period, and past its
* end to the next working days, which makes the task end later. Other
* tasks' bookings never move.
* The estimate fills the working days of the planned period in order
* (not Saturdays, Sundays or holidays; a period of only such days uses
* all its days): each day gets the assignee's free capacity (the daily
* maximum minus what other open tasks already book) before the next day
* gets anything. What does not fit in the period moves to the next
* working days after it, which makes the task end later. Other tasks'
* bookings never move.
*/
final class TaskScheduler
{
/** Bookings are made in quarter hours, like time entries. */
private const int STEP_MINUTES = 15;
/** How far past the planned end the overflow may go. */
private const int MAX_EXTRA_DAYS = 366;
@@ -51,14 +48,16 @@ final class TaskScheduler
$targets = $days;
}
$shares = self::split($minutes, count($targets));
$booked = [];
$carry = 0;
$carry = $minutes;
foreach ($targets as $index => $day) {
$wanted = $shares[$index] + $carry;
$booking = min($wanted, self::free($day, $otherMinutes, $capacityMinutes));
$carry = $wanted - $booking;
foreach ($targets as $day) {
if ($carry === 0) {
break;
}
$booking = min($carry, self::free($day, $otherMinutes, $capacityMinutes));
$carry -= $booking;
if ($booking > 0) {
$booked[$day] = $booking;
@@ -198,27 +197,6 @@ final class TaskScheduler
return $days;
}
/**
* Splits the minutes into equal quarter-hour shares; the first days get
* the remainder. Odd minutes go to the first day.
*
* @return list<int>
*/
private static function split(int $minutes, int $parts): array
{
$steps = intdiv($minutes, self::STEP_MINUTES);
$odd = $minutes % self::STEP_MINUTES;
$shares = [];
for ($index = 0; $index < $parts; $index++) {
$shares[] = (intdiv($steps, $parts) + ($index < $steps % $parts ? 1 : 0)) * self::STEP_MINUTES;
}
$shares[0] += $odd;
return $shares;
}
/**
* Books the carried minutes on the working days after the day; what
* finds no free time within MAX_EXTRA_DAYS goes on the last day tried.