I\'m looking for standards for Date/Time addition. I haven\'t been able to find any. In particular I\'m hoping to find a spec that defines what should happen when you add a mont
Joda-Time in Java chooses the previous valid date when an invalid one is created. For example, 2011-01-31 + P1M = 2011-02-28
. I believe this is the most widely chosen default choice in date-time libraries, and thus a de facto standard.
ThreeTen/JSR-310 provides a strategy pattern for this, with four choices, see the code.
More amusing is the question of what the answer to 2011-01-31 + P1M-1D
is. If you add the month, then resolve the invalid date, then subtract the day, you get 2011-02-27. But I think most users expect 2011-02-28 because the period is being added in a single lump. See how ThreeTen handles this here.
I have considered trying to write a general purpose best practices in date/time calculations, or actual spec, but haven't really had the time!