Fix WebUI: podman_parse_time() rejected int timestamps from list endpoints
Found by exercising the AJAX endpoints directly against a real running podman service (php -d display_errors=1 -r '...containers.php...') — containers.php's list action crashed with an uncaught TypeError the moment a real container existed. podman's libpod API is inconsistent about container/volume timestamp encoding: inspect-style endpoints return RFC3339 strings, but list-style endpoints (containers/json, volumes/json) return raw Unix-epoch integers for the same logical field. podman_parse_time() only accepted ?string, so any list call with a real container blew up outright rather than merely mis-rendering. Widened it to string|int|null and handle both. Verified: containers.php's list action now returns correct JSON for real running/exited containers, including their createdAt timestamps. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -42,13 +42,25 @@ function podman_format_duration(int $seconds): string
|
|||||||
return "{$minutes}m";
|
return "{$minutes}m";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Converts a libpod RFC3339 timestamp (as found in inspect output) to a Unix timestamp, or null if unparsable. */
|
/**
|
||||||
function podman_parse_time(?string $rfc3339): ?int
|
* Converts a libpod timestamp to a Unix timestamp, or null if unparsable.
|
||||||
|
* Accepts both the RFC3339 strings `inspect`-style endpoints return and
|
||||||
|
* the raw Unix-epoch integers `list`-style endpoints return for the same
|
||||||
|
* logical field (e.g. containers/json's StartedAt/Created vs. inspect's)
|
||||||
|
* — verified live against a real podman system service, not just docs.
|
||||||
|
*/
|
||||||
|
function podman_parse_time(string|int|null $value): ?int
|
||||||
{
|
{
|
||||||
if ($rfc3339 === null || $rfc3339 === '' || str_starts_with($rfc3339, '0001-01-01')) {
|
if ($value === null || $value === '') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$ts = strtotime($rfc3339);
|
if (is_int($value)) {
|
||||||
|
return $value > 0 ? $value : null;
|
||||||
|
}
|
||||||
|
if (str_starts_with($value, '0001-01-01')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$ts = strtotime($value);
|
||||||
return $ts === false ? null : $ts;
|
return $ts === false ? null : $ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user