diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/schedule-months.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib/schedule-months.ts b/src/lib/schedule-months.ts index cd109b7..829fef5 100644 --- a/src/lib/schedule-months.ts +++ b/src/lib/schedule-months.ts @@ -42,3 +42,37 @@ export function monthLabel(key: string): string { const [y, m] = key.split('-').map(Number); return `${y}年${m}月`; } + +/** 月キー → 年度キー(令和8年度は r8。4月〜翌年3月) */ +export function fiscalYearOf(month: string): string { + const [y, m] = month.split('-').map(Number); + const startYear = m >= 4 ? y : y - 1; + return `r${startYear - 2018}`; +} + +/** データに存在する年度(昇順) */ +export const fiscalYearKeys: string[] = [...new Set(monthKeys.map(fiscalYearOf))].sort(); + +/** 年度に含まれる月キー(データにある月だけ) */ +export function monthsInFiscalYear(fy: string): string[] { + return monthKeys.filter((month) => fiscalYearOf(month) === fy); +} + +/** 年度の表示(r8 → 令和8年度) */ +export function fiscalYearLabel(fy: string): string { + return `令和${Number(fy.slice(1))}年度`; +} + +/** 複数の月のいずれかに開催される行を返す */ +export function rowsInMonths(months: string[], type: 'meeting' | 'event'): Row[] { + const inMonths = (item: Item) => + datesOf(item).some((date) => months.includes(date.slice(0, 7))); + return items + .filter((item) => item.type === type && inMonths(item)) + .map((item) => item.row); +} + +/** 年度に開催される行を返す */ +export function rowsInFiscalYear(fy: string, type: 'meeting' | 'event'): Row[] { + return rowsInMonths(monthsInFiscalYear(fy), type); +} |
