'integer', 'done' => 'integer', 'seconds_per_unit' => 'integer', 'cost' => 'array', 'starts_at' => 'immutable_datetime', 'finishes_at' => 'immutable_datetime', ]; } /** Units trained by $at, never more than ordered. */ public function doneAt(CarbonImmutable $at): int { if ($at->lessThan($this->starts_at)) { return 0; } $elapsed = ($at->getTimestampMs() - $this->starts_at->getTimestampMs()) / 1000; return min($this->count, (int) floor($elapsed / $this->seconds_per_unit)); } public function building(): BelongsTo { return $this->belongsTo(Building::class); } }