function to generate array of months from selected date was created

This commit is contained in:
Vladimir Khvan 2023-02-02 16:54:28 +05:00
parent 87ce705f19
commit e289c4a0a4

View File

@ -0,0 +1,17 @@
import moment from "moment";
export const getCalendarMonths = (selectedDate) => {
// prettier-ignore
const months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Jan","Feb","Mar","Apr"];
const monthsObjs = months.map((month) => ({
key: `${selectedDate.year()}-${moment().month(month).format("M")}`,
value: month,
}));
for (let i = 12; i < 16; i++) {
monthsObjs[i] = {
key: `${selectedDate.year() + 1}` + monthsObjs[i].key.substring(4),
value: monthsObjs[i].value,
};
}
return monthsObjs;
};