feat(ranking): 주간 랭킹 기간 정책을 추가한다

This commit is contained in:
2026-06-08 15:23:08 +09:00
parent 250bebb93b
commit 5019c32145
2 changed files with 101 additions and 0 deletions

View File

@@ -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
)