Re:Ask HN: Did you encounter any leap year bugs today?
by rfoo on Sunday March 03, 2024 @04:25AM
(#39579631)
Thanks! It does this according to doc:
This method adds the specified amount to the years field in three steps:
* Add the input years to the year field
* Check if the resulting date would be invalid
* Adjust the day-of-month to the last valid day if necessary
TIL. I didn't know that Java had a builtin calendar (instead of datetime) library.
It may not have the convenient "years" method directly, but you can add an arbitrary unit of time quite easily
Example with duration:
Example with datetime: It even supports decades, centuries, eras and half days :-)For those curious about how it handles leap years: