@@ -362,27 +362,27 @@ out [Ry](https://pypi.org/project/ry/).
362362## Why aren't all operators supported for all types?
363363
364364Some operators may be conspicuously missing for certain types, even
365- though they could be implemented. For example:
365+ though they could be implemented. Whenever provides operators where their
366+ meaning is useful and can be documented clearly.
367+
368+ For example, dates and datetimes support applying itemized deltas with ` + `
369+ and ` - ` :
366370
367371``` python
368- >> > Date(2024 , 1 , 31 ) + ItemizedDateDelta(months = 1 ) # Error
372+ >> > Date(2024 , 1 , 31 ) + ItemizedDateDelta(months = 1 )
373+ Date(" 2024-02-29" )
369374```
370375
371- This is because operators are only implemented where they are * mathematically
372- intuitive* . For example, when ` a + (b + c) = (a + b) + c ` and ` (a + b) - b = a ` .
373- This isn't the case when working with months
374- or years, since adding a month to January 31st gives a different result
375- than adding a month to February 28th. To avoid confusion, these
376- operators are simply not implemented. There are methods like
377- ` add() ` and ` subtract() ` that can be used
378- instead, which don't come with the same mathematical expectations:
376+ These operators use the same calendar clamping rules as ` add() ` and
377+ ` subtract() ` . As a result, adding and then subtracting the same delta is not
378+ always reversible. Itemized deltas also support ` + ` and ` - ` with each other;
379+ these perform field-wise composition and warn by default because applying the
380+ combined delta may differ from applying its parts sequentially.
379381
380- ``` python
381- >> > Date(2024 , 1 , 31 ).add(months = 1 )
382- >> > Date(2024 , 1 , 31 ).add(ItemizedDateDelta(months = 1 ))
383- ```
382+ Operators without a generally useful interpretation remain unavailable. For
383+ example, itemized deltas cannot be multiplied or divided.
384384
385- For the same reason, the ` - ` operator between two datetimes always
385+ The ` - ` operator between two datetimes always
386386returns a {class}` ~whenever.TimeDelta ` —an exact elapsed duration where
387387subtraction is unambiguous.
388388If you need a difference in calendar units like years, months, or days,
0 commit comments