Backup #1814
| ID | 1814 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Domain/ValueObject/ExecutionDuration.php |
| Version | 3 |
| Typ |
modified |
| Größe | 2.5 KB |
| Hash | fdfcbc735b0c63b0564672ddc37b060ab699360e7ffc58b56aeae05aafc737ce |
| Datum | 2025-12-27 15:38:51 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
declare(strict_types=1);
namespace Domain\ValueObject;
// @responsibility: Immutables Value Object für Ausführungsdauer mit Zeitstempeln
use Domain\Constants;
use InvalidArgumentException;
final class ExecutionDuration
{
private \DateTimeImmutable $requestedAt;
private ?\DateTimeImmutable $respondedAt;
private function __construct(\DateTimeImmutable $requestedAt, ?\DateTimeImmutable $respondedAt)
{
if ($respondedAt !== null && $respondedAt < $requestedAt) {
throw new InvalidArgumentException('Response timestamp cannot be before request timestamp');
}
$this->requestedAt = $requestedAt;
$this->respondedAt = $respondedAt;
}
public static function start(\DateTimeImmutable $requestedAt): self
{
return new self($requestedAt, null);
}
public static function completed(\DateTimeImmutable $requestedAt, \DateTimeImmutable $respondedAt): self
{
return new self($requestedAt, $respondedAt);
}
public static function now(): self
{
return new self(new \DateTimeImmutable(), null);
}
public function complete(\DateTimeImmutable $respondedAt): self
{
return new self($this->requestedAt, $respondedAt);
}
public function completeNow(): self
{
return new self($this->requestedAt, new \DateTimeImmutable());
}
public function requestedAt(): \DateTimeImmutable
{
return $this->requestedAt;
}
public function respondedAt(): ?\DateTimeImmutable
{
return $this->respondedAt;
}
public function durationMs(): ?int
{
if ($this->respondedAt === null) {
return null;
}
$diff = $this->respondedAt->getTimestamp() - $this->requestedAt->getTimestamp();
return $diff * Constants::MS_PER_SECOND;
}
public function isCompleted(): bool
{
return $this->respondedAt !== null;
}
public function format(): string
{
$duration = $this->durationMs();
if ($duration === null) {
return 'In progress';
}
if ($duration < 1000) {
return "{$duration}ms";
}
return sprintf('%.2fs', $duration / 1000);
}
public function toArray(): array
{
return [
'requested_at' => $this->requestedAt->format('Y-m-d H:i:s.u'),
'responded_at' => $this->respondedAt?->format('Y-m-d H:i:s.u'),
'duration_ms' => $this->durationMs(),
];
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 1814 |
3 |
modified |
2.5 KB |
2025-12-27 15:38 |
| 1813 |
2 |
modified |
2.5 KB |
2025-12-27 15:38 |
| 1812 |
1 |
modified |
2.4 KB |
2025-12-27 15:38 |
← Zurück zur Übersicht