function getMonthName(monthNumber) {
const date = new Date();
date.setMonth(monthNumber - 1);
return date.toLocaleString([], { month: 'long' });
}
function getMonthName(monthNumber) {
const date = new Date();
date.setMonth(monthNumber - 1);
return date.toLocaleString([], { month: 'long' });
}
Nobody actually thinks this way, when you ask somebody what’s the next month they don’t go, oh today is the x day of the month and I’m going to add days to the current date to see what’s the next month. That’s not how vast majority of people think about this intuitively. Clearly you and people who designed Js Date API do though.
That’s how months work. Each month has a different number of days.
Yeah, it’s how months work.
In fact, this isn’t a hypothetical argument this is how date APIs work in sane languages like Java. For example:
java.time.LocalDate.of(2023, 2, 31) > java.time.DateTimeException: Invalid date 'FEBRUARY 31' java.time.LocalDate.of(2023, 2, 3) > #object[java.time.LocalDate 0x2bc77260 "2023-02-03"]
The fact that you think what Js API dies is preferable to this is frankly surreal to me.