Re: [RFC] Duration class
| From: | Andreas Heigl | Date: | Mon, 22 Jun 2026 15:34:17 +0000 |
| Subject: | Re: [RFC] Duration class | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-131459@lists.php.net to get a copy of this message | ||
Hi All
On 22.06.26 16:36, Tim Düsterhus wrote:
Attachment: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc
Hi Am 2026-06-22 10:42, schrieb Ilija Tovilo:What is the difference between new Time(12, 23, 34.567890); and new Duration::fromIso8601String('PT12H23M34.567890S'); Both define a number of hours, minutes etc. The only "difference" is that we came to see a time as starting from a certain point in time. But that is in essence just a convention and the time component of a DateTime just represents the a duration. Also the "limitation" to 24 hours is a convention (that gets blown away in DST situations. As do the 59 seconds with leapseconds) If we want to think about an improved way of handling datetimes, why not introduce a Time-class that can later be used in combination with a Date class and a Timezone class to define a point in time (or without the Timezone to define a local DateTime). After all we can already add more than 24 hours to a DateTimeInterface viaThe Time\Duration class will also implement internal “comparison handlers”, which means that direct comparisons with operators such as < will work. While reading this I asked myself why we need a specific Duration class...
setTime (see https://3v4l.org/QZnZ2#v) - so there should be no issue with creating Time-objects with more than 24 hours...
Don't get me wrong! I like the idea of a dedicated class that holds a Time-based duration. I just think we do not need a separate "Duration" and later a "Time" class when they both - in essence - hold the same information.
Just my 0.02€
Cheers
Andreas
--
,,,
(o o)
+---------------------------------------------------------ooO-(_)-Ooo-+
| Andreas Heigl |
| mailto:andreas@heigl.org N
50°22'59.5" E 08°23'58" |
| https://andreas.heigl.org
|
+---------------------------------------------------------------------+
| https://hei.gl/appointmentwithandreas
|
+---------------------------------------------------------------------+
| GPG-Key: https://hei.gl/keyandreasheiglorg
|
+---------------------------------------------------------------------+
Attachment: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc