1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
| "use strict";
| Object.defineProperty(exports, "__esModule", { value: true });
| exports.buildMonthRows = buildMonthRows;
| function formatDateKey(y, m, d) {
| return `${y}-${String(m).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
| }
| /**
| * 当月日历网格(周一至周日),含首尾空白格。
| */
| function buildMonthRows(year, month, plansByDate) {
| const firstDay = new Date(year, month - 1, 1);
| const daysInMonth = new Date(year, month, 0).getDate();
| const startOffset = (firstDay.getDay() + 6) % 7;
| const today = new Date();
| const todayKey = formatDateKey(today.getFullYear(), today.getMonth() + 1, today.getDate());
| const cells = [];
| for (let i = 0; i < startOffset; i++) {
| cells.push({
| day: null,
| dateKey: null,
| isToday: false,
| plans: [],
| });
| }
| for (let d = 1; d <= daysInMonth; d++) {
| const key = formatDateKey(year, month, d);
| cells.push({
| day: d,
| dateKey: key,
| isToday: key === todayKey,
| plans: plansByDate[key] ?? [],
| });
| }
| while (cells.length % 7 !== 0) {
| cells.push({
| day: null,
| dateKey: null,
| isToday: false,
| plans: [],
| });
| }
| const rows = [];
| for (let i = 0; i < cells.length; i += 7) {
| rows.push(cells.slice(i, i + 7));
| }
| return rows;
| }
| //# sourceMappingURL=calendarMonth.js.map
|
|