metomi/isodatetime

Addition of "conjugate" Duration to TimePoint - order of operations

MetRonnie opened this issue · 0 comments

From cylc/cylc-flow#4908

When you add a conjugate Duration such as P1M1D to a TimePoint, it seems isodatetime does + P1D + P1M internally, which I think is confusing.

This can be argued either way (I don't think ISO 8601 specifies what order is supposed to happen), but I think the order should be as is written from left to right, i.e. + P1M + P1D.

Why does the order matter, you ask? For nominal (inexact) units, addition is not associative:

>>> 2021-02-28 + P1M + P1D
2021-03-29
>>> 2021-02-28 + P1D + P1M
2021-04-01
>>> 2021-02-28 + P1M1D
2021-04-01

(I've used shorthand to represent the metomi.isodatetime.data objects)

The other side of the argument is that we should stick with the existing behaviour to avoid a breaking, possibly-painful change.

Note: If users want the addition to take place in a specific order, they should use separate Duration objects and add them to the TimePoint object in the desired order, not add Duration objects together.