aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/lib/schedule-months.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/schedule-months.ts')
-rw-r--r--src/lib/schedule-months.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/lib/schedule-months.ts b/src/lib/schedule-months.ts
new file mode 100644
index 0000000..cd109b7
--- /dev/null
+++ b/src/lib/schedule-months.ts
@@ -0,0 +1,44 @@
+// 行事予定データを月ごとに集計する(ビルド時専用)。
+//
+// 注意: このモジュールは JSON を import するため、ブラウザ用スクリプトからは読み込まないこと。
+// (カレンダー側が必要とする日付計算は src/lib/schedule-dates.ts にある)
+import meetings from '@/data/schedule/meetings.json';
+import events from '@/data/schedule/events.json';
+import { entryDates } from './schedule-dates';
+
+export type Row = { date: string; title: string; place: string; note: string; source: string };
+export type Item = { type: 'meeting' | 'event'; row: Row };
+
+export const items: Item[] = [
+ ...(meetings.rows as Row[]).map((row) => ({ type: 'meeting' as const, row })),
+ ...(events.rows as Row[]).map((row) => ({ type: 'event' as const, row })),
+];
+
+const datesOf = (item: Item) => entryDates(item.type, item.row.date, item.row.place);
+
+/** 月ごとの件数(会議・イベントの合計) */
+export const monthCounts: Record<string, number> = (() => {
+ const counts: Record<string, number> = {};
+ for (const item of items) {
+ for (const date of new Set(datesOf(item).map((d) => d.slice(0, 7)))) {
+ counts[date] = (counts[date] ?? 0) + 1;
+ }
+ }
+ return counts;
+})();
+
+/** データに存在する月(YYYY-MM、昇順) */
+export const monthKeys: string[] = Object.keys(monthCounts).sort();
+
+/** 指定した月に開催される行だけを返す */
+export function rowsInMonth(month: string, type: 'meeting' | 'event'): Row[] {
+ return items
+ .filter((item) => item.type === type && datesOf(item).some((d) => d.startsWith(month)))
+ .map((item) => item.row);
+}
+
+/** 年月の表示(2026-11 → 2026年11月) */
+export function monthLabel(key: string): string {
+ const [y, m] = key.split('-').map(Number);
+ return `${y}年${m}月`;
+}