Skip to content

Commit 4c47f5b

Browse files
committed
refactor/#134: formatToKoreanTime 함수 리팩토링
1 parent 39145e8 commit 4c47f5b

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

core/ui/src/main/java/com/yapp/core/ui/util/DateTime.kt

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.yapp.core.ui.R
55
import java.time.LocalDate
66
import java.time.LocalTime
77
import java.time.format.DateTimeFormatter
8+
import java.util.Locale
89

910
fun formatToDay(context: Context, date: String): String {
1011
return try {
@@ -24,25 +25,15 @@ fun formatTimeRange(context: Context, startTime: String?, endTime: String?): Str
2425
fun formatToKoreanTime(context: Context, time: String): String {
2526
return try {
2627
val parsedTime = LocalTime.parse(time)
27-
val hour = parsedTime.hour
28-
val minute = parsedTime.minute
29-
30-
val isAm = hour < 12
31-
val hour12 = if (hour == 0 || hour == 12) 12 else hour % 12
32-
33-
when (minute) {
34-
0 -> context.getString(
35-
if (isAm) R.string.time_format_hour else R.string.time_format_hour_pm,
36-
hour12
37-
)
38-
30 -> context.getString(
39-
if (isAm) R.string.time_format_half_hour else R.string.time_format_half_hour_pm,
40-
hour12
41-
)
42-
else -> context.getString(
43-
if (isAm) R.string.time_format_hour_minute else R.string.time_format_hour_minute_pm,
44-
hour12, minute
45-
)
28+
29+
val pattern = context.getString(R.string.time_format_base)
30+
val formatter = DateTimeFormatter.ofPattern(pattern, Locale.KOREAN)
31+
val base = parsedTime.format(formatter)
32+
33+
when (parsedTime.minute) {
34+
0 -> base
35+
30 -> context.getString(R.string.time_format_half_hour_with_base, base)
36+
else -> context.getString(R.string.time_format_hour_minute_with_base, base, parsedTime.minute)
4637
}
4738
} catch (e: Exception) {
4839
time

core/ui/src/main/res/values/strings.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
<string name="attendance_status_excused">공결</string>
99

1010
<string name="time_format_day">%1$d일</string>
11-
<string name="time_format_hour">오전 %1$d시</string>
12-
<string name="time_format_hour_pm">오후 %1$d시</string>
13-
<string name="time_format_half_hour">오전 %1$d시 반</string>
14-
<string name="time_format_half_hour_pm">오후 %1$d시 반</string>
15-
<string name="time_format_hour_minute">오전 %1$d시 %2$d분</string>
16-
<string name="time_format_hour_minute_pm">오후 %1$d시 %2$d분</string>
11+
12+
<string name="time_format_base">a h시</string>
13+
<string name="time_format_half_hour_with_base">%1$s 반</string>
14+
<string name="time_format_hour_minute_with_base">%1$s %2$d분</string>
1715
</resources>

0 commit comments

Comments
 (0)