Tim Düsterhus and Derick Rethans have proposed a new `Time\Duration` class for PHP 8.6, targeting 'stopwatch' or 'egg-timer' style durations to improve developer experience for timeout APIs. The RFC is intentionally minimal, using a seconds + nanoseconds internal representation (similar to Rust's and Java's Duration). Key design decisions discussed include: the highest constructor unit being hours (`Duration::fromHours()`), omitting floating-point total methods to avoid precision/rounding issues, accepting ISO-8601 'Period' strings (PT-prefixed only) via `fromIso8601String`, and using the `Time` namespace (consistent with Rust's `std::time`, Java's `java.time`, and Go's `time`). Community feedback raised questions about ISO 8601 serialization, namespace choice (`Time` vs `DateTime`), and whether to use `add`/`sub` methods or a single variadic `sum()` method. The RFC is positioned as the first step in a modernized PHP date/time API, following the pattern of new namespaced APIs introduced in PHP 8.2 (random), 8.4 (DOM), and 8.5 (URI).

1h 17m read timeFrom externals.io
Post cover image
638 Impressions