Skip to content

Commit bb75252

Browse files
geonhwiiiclaude
andcommitted
feat: TDD로 주간 반복 간격 기능 구현
- generateRepeatDates 함수에 weekly 반복 타입 추가 - 주간 반복 간격(7일 * interval) 처리 - 2주 간격 주간 반복 테스트 케이스 추가 - Red → Green TDD 사이클 준수 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 65a815d commit bb75252

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/__tests__/unit/repeatEvent.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,39 @@ describe('반복 간격 계산', () => {
151151

152152
expect(repeatDates).toEqual(expectedDates);
153153
});
154+
155+
test('주간 반복에 2주 간격이 적용된다', () => {
156+
// Given: 주간 반복에 2주 간격 설정이 주어졌을 때
157+
const baseEvent: Event = {
158+
id: 'test-5',
159+
title: '주간 간격 테스트',
160+
date: '2024-01-01', // 월요일
161+
startTime: '10:00',
162+
endTime: '11:00',
163+
description: '',
164+
location: '',
165+
category: '',
166+
repeat: {
167+
type: 'weekly',
168+
interval: 2, // 2주 간격
169+
endDate: '2024-02-29'
170+
},
171+
notificationTime: 0
172+
};
173+
174+
// When: 주간 반복 일정을 생성할 때
175+
const endDate = new Date('2024-02-29');
176+
const repeatDates = generateRepeatDates(baseEvent, endDate);
177+
178+
// Then: 2주씩 간격을 두고 일정이 생성되어야 한다
179+
const expectedDates = [
180+
'2024-01-01', // 원본 (1월 1일 월요일)
181+
'2024-01-15', // +2주 (1월 15일 월요일)
182+
'2024-01-29', // +2주 (1월 29일 월요일)
183+
'2024-02-12', // +2주 (2월 12일 월요일)
184+
'2024-02-26', // +2주 (2월 26일 월요일)
185+
];
186+
187+
expect(repeatDates).toEqual(expectedDates);
188+
});
154189
});

src/utils/dateUtils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ export function generateRepeatDates(event: Event, endDate: Date): string[] {
124124
while (currentDate <= effectiveEndDate) {
125125
currentDate.setDate(currentDate.getDate() + event.repeat.interval);
126126

127+
if (currentDate <= effectiveEndDate) {
128+
const dateString = formatDate(currentDate);
129+
dates.push(dateString);
130+
}
131+
}
132+
} else if (event.repeat.type === 'weekly') {
133+
const startDate = new Date(event.date);
134+
let currentDate = new Date(startDate);
135+
136+
while (currentDate <= effectiveEndDate) {
137+
currentDate.setDate(currentDate.getDate() + (7 * event.repeat.interval));
138+
127139
if (currentDate <= effectiveEndDate) {
128140
const dateString = formatDate(currentDate);
129141
dates.push(dateString);

0 commit comments

Comments
 (0)