My colleague and I have an interesting problem. We work with an old system that only returns date data in the format ddMMM
. If the day/month is in the past for the current year, then we are to assume this date applies to next year. Otherwise it applies to the current year.
So today is 4/30/2015
. If the system returned records with 12MAR
, then that date translates to 3/12/2016
. If the date reads 07MAY
, then it translates to 5/7/2015
.
However, it is unclear how to determine the year for 29FEB
since it is a leap year. We cannot instantiate it with a year without the possibility of it throwing an error. We relied on a try/catch
when trying to create a LocalDate
off it for the current year. If it catches, we assume it belongs to next year.
Is there a more kosher way to do this?
MonthDay
, as that's what you've got.Year.isLeap(long)
That's hopefully outlined the three "odd" conditions you need to account for - we don't have enough information to tell you what to do in those conditions.
See more on this question at Stackoverflow