-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: requireNotNull 로직 제거, isTodayWithinDateRange 로직 개선
- Loading branch information
1 parent
103cbc7
commit 1427e0c
Showing
3 changed files
with
32 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 27 additions & 7 deletions
34
main-domain/src/main/java/com/teamhy2/main/domain/util/DateUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,41 @@ | ||
package com.teamhy2.main.domain.util | ||
|
||
import java.time.LocalDate | ||
import java.time.format.DateTimeFormatter | ||
|
||
object DateUtil { | ||
/** | ||
* Checks if the current date is within the specified date range. | ||
* | ||
* @param startDate The start date of the range. | ||
* @param endDate The end date of the range. | ||
* @param startDateString The start date string of the range. | ||
* @param endDateString The end date string of the range. | ||
* @return True if the current date is within the range, false otherwise. | ||
*/ | ||
fun isTodayWithinDateRange( | ||
startDate: LocalDate, | ||
endDate: LocalDate, | ||
startDateString: String, | ||
endDateString: String, | ||
): Boolean { | ||
val today: LocalDate = LocalDate.now() | ||
return today.isEqual(startDate) || today.isEqual(endDate) || | ||
(today.isAfter(startDate) && today.isBefore(endDate)) | ||
val formatter = DateTimeFormatter.ofPattern("[yyyy-MM-dd][yyyy-M-d]") | ||
|
||
val startDateResult = | ||
runCatching { | ||
LocalDate.parse(startDateString, formatter) | ||
} | ||
|
||
val endDateResult = | ||
runCatching { | ||
LocalDate.parse(endDateString, formatter) | ||
} | ||
|
||
if (startDateResult.isFailure || endDateResult.isFailure) { | ||
return false | ||
} | ||
|
||
val startDate = startDateResult.getOrNull() | ||
val endDate = endDateResult.getOrNull() | ||
val todayDate: LocalDate = LocalDate.now() | ||
|
||
return todayDate.isEqual(startDate) || todayDate.isEqual(endDate) || | ||
(todayDate.isAfter(startDate) && todayDate.isBefore(endDate)) | ||
} | ||
} |