Re: [RFC] Duration class

From: Date: Fri, 17 Jul 2026 15:39:59 +0000
Subject: Re: [RFC] Duration class
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  Groups: php.internals 
Request: Send a blank email to internals+get-131997@lists.php.net to get a copy of this message
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

« previous php.internals (#131997) next »