@mantine/dates
Version:
Calendars, date and time pickers based on Mantine components
40 lines (39 loc) • 1.66 kB
JavaScript
"use client";
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
const require_get_end_of_week = require("../get-end-of-week/get-end-of-week.cjs");
const require_get_start_of_week = require("../get-start-of-week/get-start-of-week.cjs");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
//#region packages/@mantine/dates/src/components/Month/get-month-days/get-month-days.ts
function getMonthDays({ month, firstDayOfWeek = 1, consistentWeeks }) {
const start = (0, dayjs.default)((0, dayjs.default)(month).subtract((0, dayjs.default)(month).date() - 1, "day").format("YYYY-M-D"));
const startOfMonth = start.format("YYYY-MM-DD");
const endDate = require_get_end_of_week.getEndOfWeek(start.add(+start.daysInMonth() - 1, "day").format("YYYY-MM-DD"), firstDayOfWeek);
const weeks = [];
let date = (0, dayjs.default)(require_get_start_of_week.getStartOfWeek(startOfMonth, firstDayOfWeek));
while ((0, dayjs.default)(date).isBefore(endDate, "day")) {
const days = [];
for (let i = 0; i < 7; i += 1) {
days.push(date.format("YYYY-MM-DD"));
date = date.add(1, "day");
}
weeks.push(days);
}
if (consistentWeeks && weeks.length < 6) {
const lastWeek = weeks[weeks.length - 1];
const lastDay = lastWeek[lastWeek.length - 1];
let nextDay = (0, dayjs.default)(lastDay).add(1, "day");
while (weeks.length < 6) {
const days = [];
for (let i = 0; i < 7; i += 1) {
days.push(nextDay.format("YYYY-MM-DD"));
nextDay = nextDay.add(1, "day");
}
weeks.push(days);
}
}
return weeks;
}
//#endregion
exports.getMonthDays = getMonthDays;
//# sourceMappingURL=get-month-days.cjs.map