feat(home): AI 캐릭터 스냅샷 집계 기간을 정의한다

This commit is contained in:
2026-07-10 03:20:20 +09:00
parent 9288b44d5e
commit eb4df66ece
2 changed files with 61 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
package kr.co.vividnext.sodalive.v2.recommendation.domain
import java.time.LocalDateTime
import java.time.ZoneId
class RecommendationSnapshotWindowPolicy {
fun previousKstDayUtcWindow(nowUtc: LocalDateTime): RecommendationSnapshotWindow {
val previousKstDate = nowUtc
.atZone(UTC_ZONE)
.withZoneSameInstant(KST_ZONE)
.toLocalDate()
.minusDays(1)
val startUtc = previousKstDate
.atStartOfDay(KST_ZONE)
.withZoneSameInstant(UTC_ZONE)
.toLocalDateTime()
val endExclusiveUtc = previousKstDate
.plusDays(1)
.atStartOfDay(KST_ZONE)
.withZoneSameInstant(UTC_ZONE)
.toLocalDateTime()
val snapshotAt = endExclusiveUtc.minusSeconds(1)
return RecommendationSnapshotWindow(
startUtc = startUtc,
endExclusiveUtc = endExclusiveUtc,
snapshotAt = snapshotAt
)
}
companion object {
private val UTC_ZONE: ZoneId = ZoneId.of("UTC")
private val KST_ZONE: ZoneId = ZoneId.of("Asia/Seoul")
}
}
data class RecommendationSnapshotWindow(
val startUtc: LocalDateTime,
val endExclusiveUtc: LocalDateTime,
val snapshotAt: LocalDateTime
)

View File

@@ -0,0 +1,20 @@
package kr.co.vividnext.sodalive.v2.recommendation.domain
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import java.time.LocalDateTime
class RecommendationSnapshotWindowPolicyTest {
private val policy = RecommendationSnapshotWindowPolicy()
@Test
@DisplayName("KST 전날 하루를 UTC 조회 범위로 변환한다")
fun shouldConvertPreviousKstDayToUtcWindow() {
val window = policy.previousKstDayUtcWindow(LocalDateTime.of(2026, 7, 9, 21, 0, 0))
assertEquals(LocalDateTime.of(2026, 7, 8, 15, 0, 0), window.startUtc)
assertEquals(LocalDateTime.of(2026, 7, 9, 15, 0, 0), window.endExclusiveUtc)
assertEquals(LocalDateTime.of(2026, 7, 9, 14, 59, 59), window.snapshotAt)
}
}