Skip to content

Commit

Permalink
refactor: 코틀린스러운 코드로 isTodayWithinDateRange 축약
Browse files Browse the repository at this point in the history
  • Loading branch information
librarywon committed Dec 8, 2024
1 parent 1427e0c commit 50b71d1
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions main-domain/src/main/java/com/teamhy2/main/domain/util/DateUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,15 @@ object DateUtil {
endDateString: String,
): Boolean {
val formatter = DateTimeFormatter.ofPattern("[yyyy-MM-dd][yyyy-M-d]")

val startDateResult =
val startDate =
runCatching {
LocalDate.parse(startDateString, formatter)
}

val endDateResult =
}.getOrNull() ?: return false
val endDate =
runCatching {
LocalDate.parse(endDateString, formatter)
}

if (startDateResult.isFailure || endDateResult.isFailure) {
return false
}
}.getOrNull() ?: return false

val startDate = startDateResult.getOrNull()
val endDate = endDateResult.getOrNull()
val todayDate: LocalDate = LocalDate.now()

return todayDate.isEqual(startDate) || todayDate.isEqual(endDate) ||
Expand Down

0 comments on commit 50b71d1

Please sign in to comment.