test #340
|
@ -23,16 +23,24 @@ object RankingWindowCalculator {
|
||||||
fun now(prefix: String = "popular-chat-character"): RankingWindow {
|
fun now(prefix: String = "popular-chat-character"): RankingWindow {
|
||||||
val now = ZonedDateTime.now(ZONE)
|
val now = ZonedDateTime.now(ZONE)
|
||||||
val todayBoundary = now.toLocalDate().atTime(BOUNDARY_HOUR, 0, 0).atZone(ZONE)
|
val todayBoundary = now.toLocalDate().atTime(BOUNDARY_HOUR, 0, 0).atZone(ZONE)
|
||||||
val (start, endExclusive, nextBoundary) = if (now.isBefore(todayBoundary)) {
|
|
||||||
val start = todayBoundary.minusDays(1)
|
// 일일 순위는 "전날" 완료 구간을 보여주기 위해, 언제든 직전 경계까지만 집계한다.
|
||||||
Triple(start, todayBoundary, todayBoundary)
|
// 예) 2025-09-14 20:00:00 직후에도 [2025-09-13 20:00, 2025-09-14 20:00) 윈도우를 사용
|
||||||
|
val lastBoundary = if (now.isBefore(todayBoundary)) {
|
||||||
|
// 아직 오늘 20:00 이전이면, 직전 경계는 어제 20:00
|
||||||
|
todayBoundary.minusDays(1)
|
||||||
} else {
|
} else {
|
||||||
val next = todayBoundary.plusDays(1)
|
// 오늘 20:00을 지났거나 같으면, 직전 경계는 오늘 20:00
|
||||||
Triple(todayBoundary, next, next)
|
todayBoundary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val start = lastBoundary.minusDays(1)
|
||||||
|
val endExclusive = lastBoundary
|
||||||
|
|
||||||
val windowStart = start.toInstant()
|
val windowStart = start.toInstant()
|
||||||
val windowEnd = endExclusive.minusNanos(1).toInstant() // [start, end]
|
val windowEnd = endExclusive.minusSeconds(1).toInstant() // [start, end]
|
||||||
val cacheKey = "$prefix:${windowStart.epochSecond}"
|
val cacheKey = "$prefix:${windowStart.epochSecond}"
|
||||||
return RankingWindow(windowStart, windowEnd, nextBoundary.toInstant(), cacheKey)
|
// nextBoundary 필드는 기존 시그니처 유지를 위해 endExclusive(=lastBoundary)를 그대로 전달한다.
|
||||||
|
return RankingWindow(windowStart, windowEnd, endExclusive.toInstant(), cacheKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue