Hey Tim,

On Tue, Jul 14, 2026 at 3:36 PM Tim Düsterhus <[email protected]> wrote:

> That would've been my suggestion as well. I think it's only natural that
> 100% agreement on everything is impossible for a project as widely used
> as PHP.

indeed :)

> >>  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,
>
> Sorry, I'm not sure I quite understand what you are trying to say here.
>
> When discussing a Duration as in stop-watch time, I think it's natural
> to say “Usain Bolt broke the 100 m world record with 9 seconds 58
> hundreths”, which is exactly the fixed-point decimal representation that
> the `fromSeconds()` constructor also uses. For longer races one might
> say “1 minute, 40 seconds and 91 hundreths” rather than “100 seconds 91
> hundreths”, but none of the components overflow, and the “subseconds”
> are never further divided down into millis, micros, nanos, but just use
> the desired precision directly.

We could list 1000s of examples contradicting each other's argument.
However, forcing that limit drops the conversion burden to the caller,
or worse, runtime type error or the likes (I bet a few nickel on that
:). I call it DX.

> > - 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.
>
> As outlined above, I believe this special casing of the “subsecond
> boundary” is common in the real world and human communication.

The human communication part is how the Duration provides its
information. That's not correlated to how they are or can be provided.
It is just as common in the real world to have duration information in
one unit only and decimal. F.e. 234.54ms. or 3.4 hours, etc. the
set<Unit> method can extremely easily handle this. And the
inconsistency of having nanoseconds, and only nanoseconds, on top of
that makes it worse.

Cheers,
-- 
Pierre

@pierrejoye

Reply via email to