Skip to content

Commit 3e2846e

Browse files
committed
[6장_이지훈] Event 정리 + 테코
1 parent a8249a3 commit 3e2846e

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package ezhoon.chapter06
2+
3+
import java.time.Duration
4+
import java.time.LocalDateTime
5+
6+
data class Event(
7+
private val subject: String,
8+
private val from: LocalDateTime,
9+
private val duration: Duration,
10+
) {
11+
12+
fun isSatisfied(schedule: RecurringSchedule): Boolean = !(from.dayOfWeek != schedule.dayOfWeek || from.toLocalTime() != schedule.from || duration != schedule.duration)
13+
14+
fun reschedule(schedule: RecurringSchedule): Event = copy(
15+
from = LocalDateTime.of(
16+
from.toLocalDate().plusDays(daysDistance(schedule)),
17+
schedule.from
18+
),
19+
duration = schedule.duration
20+
)
21+
22+
private fun daysDistance(schedule: RecurringSchedule): Long = (schedule.dayOfWeek.value - from.dayOfWeek.value).toLong()
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ezhoon.chapter06
2+
3+
import java.time.DayOfWeek
4+
import java.time.Duration
5+
import java.time.LocalTime
6+
7+
class RecurringSchedule(
8+
private val subject: String,
9+
val dayOfWeek: DayOfWeek,
10+
val from: LocalTime,
11+
val duration: Duration
12+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package ezhoon.chapter06
2+
3+
import org.junit.jupiter.api.Assertions.*
4+
import org.junit.jupiter.api.DisplayName
5+
import org.junit.jupiter.api.Test
6+
import java.time.*
7+
8+
class EventTest {
9+
10+
@Test
11+
@DisplayName("반복일정 테스트 코드")
12+
fun recurringScheduleTest() {
13+
// given
14+
val schedule = RecurringSchedule(
15+
"회의",
16+
DayOfWeek.WEDNESDAY,
17+
LocalTime.of(10, 30),
18+
Duration.ofMinutes(30)
19+
)
20+
val meeting = Event(
21+
"회의",
22+
LocalDateTime.of(2019,5,8,10,30),
23+
Duration.ofMinutes(30)
24+
)
25+
// when
26+
27+
// then
28+
}
29+
}

0 commit comments

Comments
 (0)