UTC DB 환경인 실 서비스에서의 9시간 지연 표시 문제 해결

This commit is contained in:
dohyeons 2025-12-09 12:05:12 +09:00
parent d7e03d6b83
commit 612b46236f
1 changed files with 14 additions and 1 deletions

View File

@ -131,8 +131,21 @@ export function TableHistoryModal({
const formatDate = (dateString: string) => {
try {
// DB는 UTC로 저장, 브라우저가 자동으로 로컬 시간(KST)으로 변환
const date = new Date(dateString);
// 🚨 타임존 보정 로직
// 실 서비스 DB는 UTC로 저장되는데, 프론트엔드에서 이를 KST로 인식하지 못하고
// UTC 시간 그대로(예: 02:55)를 한국 시간 02:55로 보여주는 문제가 있음 (9시간 느림).
// 반면 로컬 DB는 이미 KST로 저장되어 있어서 변환하면 안 됨.
// 따라서 로컬 환경이 아닐 때만 강제로 9시간을 더해줌.
const isLocal =
typeof window !== "undefined" &&
(window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1");
if (!isLocal) {
date.setHours(date.getHours() + 9);
}
return format(date, "yyyy년 MM월 dd일 HH:mm:ss", { locale: ko });
} catch {
return dateString;