I'm trying to calculate dates for monthly subscriptions. I've seen many answers to use some variance of:
const oneMonthFromNow = new Date(new Date().setMonth(new Date().getMonth()+1));
But when I test this for edge cases it doesn't work as expected, some examples:
- Today: 31st march => Expected: 30th of April => Output: 1st of may (since 31 doesn't exist...?)
- Today: 30th January => Expected: 28th of February => Output: 2nd of March (what about leap years??)
Any ideas on how I can make this work without adding exception rules?