-
Notifications
You must be signed in to change notification settings - Fork 1
[REF/#628] date format 로직을 중앙화 해요. #678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
ce3f410
5210f11
fbbad6c
3284996
5aed6dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.hilingual.core.common.util | ||
|
|
||
| import java.time.LocalDate | ||
| import java.time.LocalDateTime | ||
| import java.time.format.DateTimeFormatter | ||
| import java.util.Locale | ||
|
|
||
| object DateFormatters { | ||
| val KOREAN_FULL_DATE: DateTimeFormatter = DateTimeFormatter.ofPattern("M월 d일 EEEE", Locale.KOREA) | ||
|
|
||
| val KOREAN_SHORT_DATE: DateTimeFormatter = DateTimeFormatter.ofPattern("M월 d일", Locale.KOREA) | ||
|
|
||
| val ISO_DATE: DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE | ||
| } | ||
|
|
||
| /** | ||
| * LocalDate를 한국어 전체 날짜 형식으로 변환합니다. | ||
| * @return "M월 d일 EEEE" 형식의 문자열 (예: "2월 6일 목요일") | ||
| */ | ||
| fun LocalDate.toKoreanFullDate(): String = this.format(DateFormatters.KOREAN_FULL_DATE) | ||
|
|
||
| fun LocalDateTime.toKoreanFullDate(): String = this.format(DateFormatters.KOREAN_FULL_DATE) | ||
|
|
||
| /** | ||
| * LocalDate를 한국어 짧은 날짜 형식으로 변환합니다. | ||
| * @return "M월 d일" 형식의 문자열 (예: "2월 6일") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇게 변환 예시 써주신 게 되게 좋은 것 같아요!! 세심하다🥹 |
||
| */ | ||
| fun LocalDate.toKoreanShortDate(): String = this.format(DateFormatters.KOREAN_SHORT_DATE) | ||
angryPodo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| fun LocalDateTime.toKoreanShortDate(): String = this.format(DateFormatters.KOREAN_SHORT_DATE) | ||
|
|
||
| /** | ||
| * LocalDate를 ISO 날짜 형식으로 변환합니다. | ||
| * @return "yyyy-MM-dd" 형식의 문자열 (예: "2026-02-06") | ||
| */ | ||
| fun LocalDate.toIsoDate(): String = this.format(DateFormatters.ISO_DATE) | ||
|
|
||
| fun LocalDateTime.toIsoDate(): String = this.format(DateFormatters.ISO_DATE) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사용하지 않는 import 정리해주세요! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,7 @@ import com.hilingual.core.common.provider.LocalTracker | |
| import com.hilingual.core.common.trigger.LocalDialogTrigger | ||
| import com.hilingual.core.common.trigger.LocalMessageController | ||
| import com.hilingual.core.common.util.UiState | ||
| import com.hilingual.core.common.util.toKoreanFullDate | ||
| import com.hilingual.core.designsystem.component.button.HilingualButton | ||
| import com.hilingual.core.designsystem.component.textfield.HilingualLongTextField | ||
| import com.hilingual.core.designsystem.theme.HilingualTheme | ||
|
|
@@ -542,7 +543,7 @@ private fun DateText( | |
| val selectedDate = selectedDateProvider() | ||
|
|
||
| val formattedDate = remember(selectedDate) { | ||
| selectedDate.format(DATE_FORMATTER) | ||
| selectedDate.toKoreanFullDate() | ||
| } | ||
|
|
||
| Text( | ||
|
|
@@ -552,9 +553,6 @@ private fun DateText( | |
| ) | ||
| } | ||
|
|
||
| private val DATE_FORMATTER: DateTimeFormatter = | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요기도 formatter 없애면서 사용하지 않는 import문이 생겼을 것 같은데 확인 부탁드려요~! |
||
| DateTimeFormatter.ofPattern("M월 d일 EEEE", Locale.KOREAN) | ||
|
|
||
| private fun createTempImageFile(context: Context): Pair<Uri, File> { | ||
| val imageFile = File.createTempFile("camera_", ".jpg", context.cacheDir) | ||
| val uri = FileProvider.getUriForFile( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이건 관점이 궁금해서 남기는 코멘트인데요.🤔
만약 다른 개발자가 다른 형태로 파싱을 하고 싶은 경우에는 (나현이는 "YYYY.MM.dd" 형태, 저는 "HH:mm:SS"로) 어떻게 하는게 좋다고 생각하나요?
먼저 저의 의견은
DateFormtter.kt를 만든 핵심 목적이 날짜 포맷 문자열이 여기저기 흩어지는걸 방지 하기 위함이니, 패턴을 인자로 받는 범용 함수를 열어두면 표준화가 깨진다고 생각합니다. 따라서 새로운 포맷이 필요하다면 객체에 상수로 추가해 재사용성을 높이도록 하는게 좋다고 생각합니다.다른 관점으로는.. 정말 일회성으로만 쓰이는 포맷이 많다면 패턴을 직접 받는 함수를 사용할 수 있다고 생각합니다. 그러나 일관성을 깨뜨린다고 생각이 드네요.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 기본적으로는 포맷 문자열이 여기저기 흩어지는 걸 막는 게 이 유틸의 핵심 목적이라고 생각해서 말씀하신 것처럼 패턴을 인자로 받는 범용 함수는 지양하는 쪽에 동의합니다 !!
그래서 여러 화면 / 여러 로직에서 재사용될 가능성이 있는 포맷이라면
DateFormatters객체에 명시적인Formatter상수로 추가하는 게 맞다고 봅니다.이 방식이 프로젝트에서 허용된 날짜 표현을 자연스럽게 문서화하는 효과도 있다고 생각해요.
저 역시 정말 일회성인 경우는
DateTimeFormatter.ofPattern()을 직접 쓰되 주석으로 왜 커스텀이 필요한지 간단히 적어두거나 한 파일 내에서만 쓰인다면 private val로 분리하는 것도 방법이겠지만 .. 의도적으로 사용 범위를 제한해서 이건 예외적인 표현이다라는 점이 드러나게 하는 게 중요할 것 같아요. 이미 날짜 포맷을 위한 유틸이 존재하는 상황에서 이를 사용하지 않는다면 오히려 왜 이 포맷만 예외인지를 이해하기 어려워질 수 있다는 생각도 듭니다..!