Re: [PHP-DEV] [RFC] Duration class

[email protected] (Tim Düsterhus) Fri, 17 Jul 2026 17:39:59 +0200
Newsgroups php.internals
Message-ID <[email protected]>
Hi

On 7/16/26 16:25, Pierre Joye wrote:
> I think we are in different realities ;-).
> 
> More seriously, and some random weekly internals on reddit made me realize
> my point was not maybe not clear.
I had already replied on Reddit before I had seen your email here. Let 
me link the thread for further reference:

https://www.reddit.com/r/PHP/comments/1uxnmsp/comment/oy26ht9/

 From what I understand there was a misunderstanding about the behavior 
of the `Duration::fromSeconds()` constructor in that it would also limit 
the `$seconds` value (to `59` I assume). This is false, all of the 
following would be perfectly legal:

     Duration::fromSeconds(120); // Two minutes
     Duration::fromSeconds(86_400); // One 24-hour-day
     Duration::fromSeconds(31_556_925,
                           43_200_000); // One solar year according
                                        // to WolframAlpha.

Only the (optional) `$nanoseconds` parameter is limited in that it must 
be smaller than “1 second” to achieve the “fixed point decimal” 
semantics. The `fromNanoseconds()` constructor that only takes 
nanoseconds will allow overflow into larger units as will all the other 
constructors. The injectivity is on a per-constructor basis.

You can also check the proof-of-concept implementation, while it is 
non-authoritative, it correctly implements the proposed overflow and 
range-checking semantics.

Best regards
Tim Düsterhus