lion/packages/calendar/src/utils/createMultipleMonth.js
Mikhail Bashkirov 9fc5488175 feat(calendar): add reusable calendar
Co-authored-by: Erik Kroes <erik.kroes@ing.com>
Co-authored-by: Gerjan van Geest <gerjan.van.geest@ing.com>
Co-authored-by: Thijs Louisse <thijs.louisse@ing.com>
Co-authored-by: Thomas Allmer <thomas.allmer@ing.com>
2019-05-13 17:46:00 +02:00

26 lines
743 B
JavaScript

import { createMonth } from './createMonth.js';
export function createMultipleMonth(
date,
{ firstDayOfWeek = 0, pastMonths = 0, futureMonths = 0 } = {},
) {
const multipleMonths = {
months: [],
};
for (let i = pastMonths; i > 0; i -= 1) {
const pastDate = new Date(date);
pastDate.setMonth(pastDate.getMonth() - i);
multipleMonths.months.push(createMonth(pastDate, { firstDayOfWeek }));
}
multipleMonths.months.push(createMonth(date, { firstDayOfWeek }));
for (let i = 0; i < futureMonths; i += 1) {
const futureDate = new Date(date);
futureDate.setMonth(futureDate.getMonth() + (i + 1));
multipleMonths.months.push(createMonth(futureDate, { firstDayOfWeek }));
}
return multipleMonths;
}