Skip to content

Commit 6287c38

Browse files
committed
[NDGL-118] feature: 장소 상세 조회 응답 필드 regularOpeningHours를 placeInfo openingHours 필드로 바꿔주는 확장함수 추가
1 parent e41e6ab commit 6287c38

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

  • feature/travel/src/main/java/com/yapp/ndgl/feature/travel/model

feature/travel/src/main/java/com/yapp/ndgl/feature/travel/model/PlaceInfo.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package com.yapp.ndgl.feature.travel.model
22

33
import com.yapp.ndgl.core.util.formatDecimal
44
import com.yapp.ndgl.data.travel.model.PlaceDetailResponse
5+
import java.time.DayOfWeek
6+
import java.time.LocalDate
7+
import java.time.format.DateTimeFormatter
58
import kotlin.time.Duration
69
import kotlin.time.Duration.Companion.hours
710

@@ -59,3 +62,25 @@ fun PlaceDetailResponse.toPlaceInfo(): PlaceInfo {
5962
websiteUrl = place.websiteUri,
6063
)
6164
}
65+
fun List<String>?.toOpeningHours(startDate: String, day: Int): String? {
66+
if (this.isNullOrEmpty() || startDate.isBlank()) return null
67+
68+
val targetDayOfWeek = runCatching {
69+
val travelStartDate = LocalDate.parse(startDate, DateTimeFormatter.ISO_LOCAL_DATE)
70+
val targetDate = travelStartDate.plusDays((day - 1).toLong())
71+
targetDate.dayOfWeek
72+
}.getOrNull() ?: return null
73+
74+
val dayOfWeekName = when (targetDayOfWeek) {
75+
DayOfWeek.MONDAY -> "월요일"
76+
DayOfWeek.TUESDAY -> "화요일"
77+
DayOfWeek.WEDNESDAY -> "수요일"
78+
DayOfWeek.THURSDAY -> "목요일"
79+
DayOfWeek.FRIDAY -> "금요일"
80+
DayOfWeek.SATURDAY -> "토요일"
81+
DayOfWeek.SUNDAY -> "일요일"
82+
}
83+
84+
val openingHour = this.find { it.startsWith(dayOfWeekName) }
85+
return openingHour?.substringAfter(":")?.trim()
86+
}

0 commit comments

Comments
 (0)