Hi
Am 2026-06-19 18:26, schrieb Marc B.:
> 1. Why `seconds` is always positive with separate `negative` boolean? I
> don't get the reason behind that logic and it puts additional effort on
> the user reading these values. A negative Duration should just be
> negative seconds. Nanoseconds on the other hand should always between 0
> and 999_999_999.
This is answered in the “design considerations” section of the RFC. Did
you miss that one? With regard to your specific suggestion of only the
seconds should be negative: How do you represent a Duration of negative
0.5 seconds then?
> 2. fromIso8601String should just be fromIso8601. The name implies a
> string already and the argument type defines it as well.
See my sibling reply to Larry with regard a possible rename. With regard
to the `String` suffix specifically. I find it important for several
reasons:
- Horizontal consistency with `Dom\HTMLDocument::createFromString()`
(which also has `createFromFile()` with an identical signature).
- The lack of method overloading. There could possibly be an ISO-8601
object that might require a slightly different signature so that a
simple union type is insufficient.
- Just “from ISO-8601” sounds like an incomplete sentence (and “from
ISO-8601 period” does as well). I would add the “string” part in my
spoken communication as well, so I feel it should also be there in the
method name.
> 3. fromSeconds is the only initiator with a second nanoseconds
> argument. That feels a bit inconsistent from consistency POV.
See “design considerations”.
> Also, it's not just applying these values because, to be valid, there
> needs to be some calculation be done.
This is incorrect, as demonstrated by the proof-of-concept userland
implementation.
> 4. You have some operator methods defined (+add, -sum, /multiplyBy,
> <>=compare, what about other operators?
What are you looking for?
> 5. Did you thought of supporting float on the initializer methods?
See the sub-thread started by Seifeddine.
> 6. You should at least mention that this class works with a fixed
> definition of e.g. how long a minute is - no leaps tz handling here.
> Which is the correct approach for it.
I believe the “Introduction” section (and the non-normative userland
implementation) was pretty clear on that the class represents
“stop-watch time”, not something related to clocks. But for completeness
I have just added a PHPDoc comment to that effect to the class itself
(in addition to the existing PHPDoc on the methods).
> 7. Naming consistency ... add/sub vs. multiplyBy. Why not
> addBy/sub[tract]By or multiply to be more consistent?
I don't think “add by” and “sub(tract) by” is correct grammar. The `By`
on `divideBy` was a deliberate choice to make it clear that the Duration
is the dividend and the given integer is the divisor, because this isn't
entirely clear using use `divide`. For multiplication as the inverse of
division we added it for consistency (even though it doesn't matter
there, because multiplication is commutative).
This also roughly matches Java's naming of `multipliedBy` / `dividedBy`
and `plus` / `minus`.
> 8. negative vs. isNegative
Please provide a concrete suggestion.
> 9. negate() I would expect to get back a negative Duration. Also, it
> sounds like modifying the duration but I'm assuming a new instance gets
> returned. What about inverted()?
The class is `readonly`, so yes, a new instance gets returned.
`negated()` is also something I thought of, which would also work with
`multipliedBy()` and `dividedBy()` as in Java, but (as not a native
speaker of English) I believe this naming pattern breaks down for the
addition / subtraction. Ignace's suggestion of just having `sum()` might
solve this, though.
> 10. On assuming the duration is immutable. Does the medifier function
> still return the same object for the same resulting durations?
I don't understand the question.
> I have spend quite some time experimenting with building a good
> date/time API matching PHP. What I came up with went into an
> experimental but already working library in PHP without using the
> available date/calendar extension.
> <https://github.com/marc-mabe/php-timelib>
Yes, that repository is referenced in the backwards incompatible changes
section.
Best regards
Tim Düsterhus