A bit of an odd business request just came up. We have contracts that span multiple years. The system maintains the contract's End Date. I have to determine the End Date's same calendar date, but for the current year if it hasn't passed this year, or the next year if it has passed this year.
For example, as of today, 2020-01-23:
Case 1:
Input: Contract End Date of 2022-07-01
Expected Output: 2020-07-01 (because 2020-07-01 hasn't passed yet)
Case 2:
Input: Contract End Date of 2022-01-05
Expected Output: 2021-01-05 (because 2020-01-05 has already passed)
I've never posted a question on SO without some "what did you try so far" code, but I'm at a complete loss here. I imagine I could string-manipulate the heck out the dates, and do some funky things to find out if the date passed, etc. But is this requirement anyone has ever worked on, or is up for a challenge? :-) Even guidance an not code would help. Then I could edit the question with what I come up with.
EDIT:
Rephrasing the question in another way, given a future date, how can I determine the next occurrence of that day/month of that future date, based off "today".
On 2020-01-23, take 2022-07-01 and get to 2020-07-01 (the next occurrence of July 1)
On 2020-01-23, take 2024-01-05 and get to 2021-01-05 (the next occurrence of Jan 5)