feat(content-ranking): 랭킹 주간 기간 정책을 추가한다
This commit is contained in:
@@ -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
|
||||
)
|
||||
Reference in New Issue
Block a user