feat: due resolution and cascade math

Also: StoresUtc trait normalizes datetime casts to UTC (controller ruling).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
nikita.hohlov
2026-09-04 06:19:00 -03:00
parent 774e0bce1a
commit e48e48aa4a
9 changed files with 297 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Scheduling;
use Carbon\CarbonImmutable;
final class Cascade
{
/**
* Точки каскада между стартом и днём срока: старт, затем каждый раз, когда
* до срока остаётся вдвое меньше дней, до одного дня. Обе даты локальные
* полуночи в одном поясе. Возвращает локальные полуночи по возрастанию.
*
* @return list<CarbonImmutable>
*/
public static function points(CarbonImmutable $fireStart, CarbonImmutable $dueDay): array
{
$d = (int) round($fireStart->diffInDays($dueDay));
$points = [];
while ($d >= 1) {
$points[] = $dueDay->subDays($d);
$d = intdiv($d, 2);
}
return $points;
}
}