Hi Am 2026-06-18 16:18, schrieb Seifeddine Gmati:
- Is there a reason the highest unit is seconds not hours?
The highest unit supported by the constructors is hours (`Duration::fromHours()`). The internal representation uses a seconds + nanoseconds pair for the reasons outlined in the design considerations, similarly to Rust’s and Java’s Duration. 68 years on 32-bit systems and 21× the age of the universe on 64-bit systems should be plenty.
- The RFC specifies `Duration::fromIso8601String`, but there does not seem to be a method to turn the duration itself back into an ISO 8601 string. is there a reason for that?
The best reason there probably is “the proposed API is intentionally minimal”.
There are probably also some decisions to be made for the re-stringification into ISO-8601: Should it stringify straight into `sprintf("PT%d.%09dS", $seconds, $nanoseconds)` or should it try to use “as large units as possible” (i.e. minutes and hours). The correct answer might depend on the use case and thus it's probably better to move this decision to the PHP 8.7 cycle :-)
- I think it would be nice to have methods that return the total duration as a specific unit as a floating point, e.e.g., `getTotalSeconds()`, was this considered?
Derick and I haven't discussed this, but the “minimal API” applies here as well. Floating point versions we specifically left out (for now), because we didn't want to go into the precision / rounding question. As an example how many nanoseconds should `1.4` be? The internal representation of that float is `1.3999999999999999`.
Best regards Tim Düsterhus
