-- 달력 행렬: 이번 달의 각 주 시작일 → 주마다 7일matrix :: Day -> [[Day]]matrix today = [ [w `addDays` i | i <- [0 .. 6]] -- eachDayOfInterval { start = w, end = w + 6 } | w <- eachWeekOfInterval (startOfMonth today) (endOfMonth today) ]-- 첫 주·마지막 주에는 앞뒤 달 날짜가 섞인다
-- 겹치는 이벤트를 나란히 놓는다: 시작 순으로, 비어 있는 가장 낮은 레인에assign :: [Event] -> [(Event, Lane)]assign = go [] . sortOn (\e -> (start e, end e)) where go _ [] = [] go lanes (e : es) = (e, l) : go (set l (end e) lanes) es where l = fromMaybe (length lanes) (findIndex (<= start e) lanes) -- 끝난 레인 중 가장 낮은 것-- 레인 수 = 동시에 겹치는 최대 개수 (구간 그래프의 탐욕 색칠) — 가능한 한 적은 레인으로 모두 덮는 최적해다-- 겹치는 것끼리 그룹으로 묶어 그룹마다 total 을 센다groups :: [Event] -> [[Event]] -- 다음 시작 < 그룹의 최대 끝이면 같은 그룹style (lane, total) = { left = lane / total * 100%, width = 100% / total }assign [A 9 11, B 10 12, C 11 13] == [(A, 0), (B, 1), (C, 0)] -- total 2
-- 특정 날짜가 든 주의 7일weekDays :: Bool -> Date -> [Date] -- iso 기본값 True: getWeekDays(date) 는 월~일weekDays iso d = [start `addDays` i | i <- [0..6]] where start = startOf (if iso then IsoWeek else Week) d-- IsoWeek: ISO 8601, 월요일 시작 (캘린더 UI 에 주로) — dayjs.extend(isoWeek) 필요-- Week: 로케일을 따른다 — 기본 en·ko 는 일요일, en-gb 는 월요일weekDays True "2025-10-28" == ["2025-10-27", …, "2025-11-02"]