Uses Temporal.Duration.compare: -1 when a is shorter, 0 when equal, 1 when a is longer.
Equality is by length, not by spelling — “PT60M” and “PT1H” compare 0, as do “P1D” and “PT24H” absent a relativeTo.
relativeTo is required whenever a calendar unit (year/month/week) appears on either side; without it, returns null. Note the asymmetry with addDuration/subtractDuration (A2): Temporal.Duration.compare does accept relativeTo, while .add/.subtract do not, so calendar-unit durations are comparable here even though they cannot be combined there. durationAs and normalizeDuration (A3) carry the same relativeTo rule as this function.
The anchor genuinely decides the answer rather than merely unblocking it: “P1M” is longer than “P30D” relative to January (31 days) and shorter relative to February 2024 (29).
It matters for non-calendar units too when it names a zoned instant — across a DST spring-forward, “P1D” is 23 real hours and so compares shorter than “PT24H”.
Returns null if either operand is not a valid ISO 8601 duration string, or relativeTo is invalid.