Re: [RFC] Duration class
| From: | Pierre Joye | Date: | Tue, 14 Jul 2026 03:20:37 +0000 |
| Subject: | Re: [RFC] Duration class | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-131907@lists.php.net to get a copy of this message | ||
Hi Tim,
On Mon, Jul 13, 2026 at 9:22 PM Tim Düsterhus <tim@bastelstu.be> wrote:
> As for the specific case of “the constructors should be injective
> functions”, you missed the second half of the quoted sentence: “and also
> based on our experience of working with dates and times both in PHP and
> other programming languages”,
ok, let's agree to disagree here, it is hard to agree on "experiences". :)
> although native support for fixed-point
> decimals would certainly made the API nicer.
What would be nicer is common practice and prior art(s). The setSecond
makes no sense as of now for two reaons:
- the limits because an instant is measured using 24 hours, 60 minutes
per hour, 60 seconds per minutes etc. does not mean a duration common
case do so. Common, and that's barely arguable, a duration is rarely
measured like an instant in time. If ever,
- it is awkward to have nanoseconds in setSeconds out of nowhere. I
understand some external factor (other entities) leading to that
decision but that creates illogical, inconsistent and confusing
semantic boundaries. A box can contain apples does not mean
setDimension should use apples with a limit on top. Or an apple can be
used with a box that does not make an apple's unit in square feet.
I like that RFC, but it adds confusions and limitations from what is
supposed to be a simple first step. As it stands now, despite the fact
that I would love to see it, I tend towards a no.
Best,
--
Pierre
@pierrejoye