Joda DateTime .withDayOfMonth(31) not returning max value

Viewed 67

I noticed that DateTime.now().withDayOfMonth(31) currently in February 2022 results in "27.02." instead of the expected "28.02". However DateTime.now().withDayOfMonth(28) works as expected. As of the Documentation of DateTimeField.set(long instant, int value) which is called by .withDayOfMonth(), this seems like a bug:

If setting this field would make other fields invalid, then those fields may be changed. For example if the current date is the 31st January, and the month is set to February, the day would be invalid. Instead, the day would be changed to the closest value - the 28th/29th February as appropriate.

0 Answers
Related