feat(ranking): 주간 랭킹 기간 정책을 추가한다
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package kr.co.vividnext.sodalive.v2.ranking.domain
|
||||
|
||||
import java.time.DayOfWeek
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import java.time.ZonedDateTime
|
||||
import java.time.temporal.TemporalAdjusters
|
||||
|
||||
class CreatorRankingPeriodPolicy {
|
||||
fun resolveLastCompletedWeek(now: ZonedDateTime): CreatorRankingPeriod {
|
||||
val nowKst = now.withZoneSameInstant(KST_ZONE)
|
||||
val thisWeekMonday = nowKst.toLocalDate()
|
||||
.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY))
|
||||
.atStartOfDay()
|
||||
return CreatorRankingPeriod(
|
||||
startInclusiveKst = thisWeekMonday.minusWeeks(1),
|
||||
endExclusiveKst = thisWeekMonday
|
||||
)
|
||||
}
|
||||
|
||||
fun toUtcRange(period: CreatorRankingPeriod): CreatorRankingUtcRange {
|
||||
return CreatorRankingUtcRange(
|
||||
startInclusiveUtc = period.startInclusiveKst.atZone(KST_ZONE).withZoneSameInstant(UTC_ZONE).toLocalDateTime(),
|
||||
endExclusiveUtc = period.endExclusiveKst.atZone(KST_ZONE).withZoneSameInstant(UTC_ZONE).toLocalDateTime()
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val KST_ZONE: ZoneId = ZoneId.of("Asia/Seoul")
|
||||
private val UTC_ZONE: ZoneId = ZoneId.of("UTC")
|
||||
}
|
||||
}
|
||||
|
||||
data class CreatorRankingPeriod(
|
||||
val startInclusiveKst: LocalDateTime,
|
||||
val endExclusiveKst: LocalDateTime
|
||||
)
|
||||
|
||||
data class CreatorRankingUtcRange(
|
||||
val startInclusiveUtc: LocalDateTime,
|
||||
val endExclusiveUtc: LocalDateTime
|
||||
)
|
||||
Reference in New Issue
Block a user