|
|
|
|
|
by jimminy
1773 days ago
|
|
Plus/Increment/Add 1 month, does have one single meaning, it's that the outcome may be invalid that is the issue. "2021-01-31".plus(unit="Month", size=1) => "2021-02-31" But nobody really wants that, because it's not a valid date. So implicitly the library is deciding to return a valid date. A library could be written to just provide invalid dates, and let the end user handle any errors. That library could also include an explicit validation method that takes a date and returns a valid one. "2021-02-31".coerceToValid() => "2021-02-28" // Overflow == Max "2021-02-31".coerceToValid(asDays=True) => "2021-03-03" // Overflow Carries (to the right) In fact the library, that provides an ignorant response and no contract on validity would hold to the associative property, it just wouldn't be as ergonomic. |
|