Conversation
…tests to use UTC for date handling
…d add JSON formatting annotations
Contributor
Author
UTC 작동 흐름1. 백엔드: 요청 수신 시점 (UTC 생성)// DiaryService.java:86
OffsetDateTime dateTime = OffsetDateTime.now(ZoneOffset.UTC);
// 예: 2024-12-20T10:30:00.000Z (UTC 기준)
2. 엔티티: 자동 타임스탬프 생성 (UTC)// Diary.java:63-68
@PrePersist
protected void onCreate() {
if (this.createdAt == null) {
this.createdAt = OffsetDateTime.now(ZoneOffset.UTC);
// 예: 2024-12-20T10:30:00.000Z
}
}
3. 데이터베이스: UTC로 저장// MySQL에 저장되는 값
createdAt: 2024-12-20 10:30:00 (UTC 시간대로 저장)
dateTime: 2024-12-20 10:30:00 (UTC 시간대로 저장)
4. API 응답: UTC 정보 포함하여 반환// DiaryResponseDto.java:34-39
@Schema(description = "일기 작성 날짜 및 시간 (UTC 기준, ISO-8601 형식).
프론트엔드에서는 사용자의 로컬 타임존으로 변환하여 표시해야 합니다.",
example = "2024-05-20T10:00:00.000Z")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
private final OffsetDateTime dateTime;// API 응답 (JSON)
{
"dateTime": "2024-12-20T10:30:00.000Z", // ← Z = UTC 표시
"createdAt": "2024-12-20T10:30:00.000Z" // ← Z = UTC 표시
}
5. 프론트엔드: 로컬 시간으로 변환 (클라이언트 측)// 프론트엔드 예시 (JavaScript)
const utcTime = "2024-12-20T10:30:00.000Z"; // 서버에서 받은 UTC 시간
// 브라우저/앱의 로컬 타임존으로 변환
const localTime = new Date(utcTime);
// 한국(KST, UTC+9): 2024-12-20 19:30:00
// 미국 뉴욕(EST, UTC-5): 2024-12-20 05:30:00
// 일본(JST, UTC+9): 2024-12-20 19:30:00
// 표시
console.log(localTime.toLocaleString());
전체 흐름 요약핵심 포인트
이 방식으로 시간대 이슈 없이 일관된 시간을 저장하고 표시할 수 있습니다. |
5 tasks
chwwwon
reviewed
Jan 16, 2026
|
|
||
| @Column(nullable = false, updatable = false) | ||
| private LocalDateTime createdAt; | ||
| private OffsetDateTime createdAt; |
Contributor
There was a problem hiding this comment.
OffsetDateTime을 사용하는 도메인에 공통적으로 적용되는 리뷰입니다.
MySQL의 DATETIME / TIMESTAMP는 offset 정보를 저장하지 않아서 버전에 따라
- offset 손실
- 자동 변환 오류
- 런타임 매핑 에러 가능
등의 문제가 발생할 수 있다고 합니다.
코파일럿이 아래와 같이 제안해주었는데 OffsetDateTimeAttributeConverter 파일 추가를 고려해보는 것도 좋을 것 같아요!
권장 수정 (가장 안전한 방법)
👉 JPA AttributeConverter 추가 (DB 변경 없이 해결)
새 파일 추가
src/main/java/zim/tave/memory/config/OffsetDateTimeAttributeConverter.java
@Converter(autoApply = true)
public class OffsetDateTimeAttributeConverter
implements AttributeConverter<OffsetDateTime, Timestamp> {
@Override
public Timestamp convertToDatabaseColumn(OffsetDateTime odt) {
return odt == null ? null : Timestamp.from(odt.toInstant());
}
@Override
public OffsetDateTime convertToEntityAttribute(Timestamp ts) {
return ts == null ? null
: OffsetDateTime.ofInstant(ts.toInstant(), ZoneOffset.UTC);
}
}
chwwwon
reviewed
Jan 16, 2026
| @Schema(description = "보드 생성 시각", example = "2025-12-01T14:20:00") | ||
| private String createdAt; | ||
| @Schema(description = "보드 생성 시각 (UTC 기준, ISO-8601 형식). 프론트엔드에서는 사용자의 로컬 타임존으로 변환하여 표시해야 합니다.", example = "2025-12-01T14:20:00.000Z") | ||
| @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX") |
Contributor
There was a problem hiding this comment.
현재 각 DTO 필드마다 @jsonformat이 개별 지정되어 있는데, 이 경우 "Z" / "+00:00" 혼재 가능성이 있어 전역 Jackson 설정으로 UTC + ISO-8601 고정하는 방법은 어떨까요?
application.yml에 아래와 같이 추가하는 방법도 있고, config를 추가하는 방법도 있으니 고려해보면 좋을 것 같아용
spring:
jackson:
time-zone: UTC
serialization:
write-dates-as-timestamps: false
…ateTime serialization and deserialization
…into refactor/66-UTC_migration
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


🔗 Related Issue
📝 Description
기획 배경 및 비즈니스 문제
🛠 Changes
DTO & 도메인 타입 변경 (테스트 코드에도 반영)
LocalDateTime createdAt → OffsetDateTime createdAt으로 변경하여 UTC 정보 손실 방지
API 문서화 개선
Swagger Schema 업데이트: 모든 OffsetDateTime 필드에 다음 정보 추가
UTC 기준 명시
ISO-8601 형식 명시
프론트엔드 변환 가이드 포함
예시에 "Z" 포함 (예: "2024-05-20T10:00:00.000Z")
JSON 직렬화 설정
@jsonformat 어노테이션 추가: ISO-8601 형식(yyyy-MM-dd'T'HH:mm:ss.SSSXXX)으로 직렬화하여 UTC 정보 포함
✅ Test Checklist