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

This commit is contained in:
2026-06-24 12:36:34 +09:00
parent af5f250abe
commit d62ce35912
2 changed files with 90 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
package kr.co.vividnext.sodalive.v2.content.ranking.domain
import java.time.DayOfWeek
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.temporal.TemporalAdjusters
class AudioRankingPeriodPolicy {
fun resolveLastCompletedWeek(now: ZonedDateTime): AudioRankingPeriod {
val nowKst = now.withZoneSameInstant(KST_ZONE)
val thisWeekMonday = nowKst.toLocalDate()
.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY))
.atStartOfDay()
return AudioRankingPeriod(
startInclusiveKst = thisWeekMonday.minusWeeks(1),
endExclusiveKst = thisWeekMonday
)
}
fun toUtcRange(period: AudioRankingPeriod): AudioRankingUtcRange {
return AudioRankingUtcRange(
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 AudioRankingPeriod(
val startInclusiveKst: LocalDateTime,
val endExclusiveKst: LocalDateTime
)
data class AudioRankingUtcRange(
val startInclusiveUtc: LocalDateTime,
val endExclusiveUtc: LocalDateTime
)