Skip to content

Commit 4c9b27e

Browse files
committed
Refactor: 포멧로직 ui 계층 책임 이전
1 parent 5000a6c commit 4c9b27e

4 files changed

Lines changed: 19 additions & 24 deletions

File tree

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.threegap.bitnagil.domain.routine.model
22

3-
import java.time.LocalTime
4-
import java.time.format.DateTimeFormatter
5-
import java.util.Locale
6-
73
data class Routine(
84
val routineId: String,
95
val routineName: String,
@@ -14,19 +10,4 @@ data class Routine(
1410
val subRoutineNames: List<String>,
1511
val subRoutineCompleteYn: List<Boolean>,
1612
val recommendedRoutineType: RecommendedRoutineType?,
17-
) {
18-
private val koreanLocale = Locale.KOREAN
19-
private val executionTimeFormatter12 = DateTimeFormatter.ofPattern("a h:mm", koreanLocale)
20-
21-
val formattedExecutionTime: String =
22-
try {
23-
val time = LocalTime.parse(executionTime)
24-
if (time == LocalTime.MIDNIGHT) {
25-
"하루종일"
26-
} else {
27-
time.format(executionTimeFormatter12)
28-
}
29-
} catch (e: Exception) {
30-
"시간 미정"
31-
}
32-
}
13+
)

presentation/src/main/java/com/threegap/bitnagil/presentation/home/component/template/RoutineSection.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import androidx.compose.ui.unit.dp
1212
import com.threegap.bitnagil.designsystem.BitnagilTheme
1313
import com.threegap.bitnagil.presentation.home.component.block.RoutineItem
1414
import com.threegap.bitnagil.presentation.home.model.RoutineUiModel
15-
import com.threegap.bitnagil.presentation.home.util.formatExecutionTime
15+
import com.threegap.bitnagil.presentation.home.util.formatExecutionTime24Hour
1616

1717
@Composable
1818
fun RoutineSection(
@@ -26,7 +26,7 @@ fun RoutineSection(
2626
horizontalArrangement = Arrangement.spacedBy(8.dp),
2727
) {
2828
Text(
29-
text = routine.executionTime.formatExecutionTime(),
29+
text = routine.executionTime.formatExecutionTime24Hour(),
3030
style = BitnagilTheme.typography.body2Medium,
3131
color = BitnagilTheme.colors.coolGray10,
3232
modifier = Modifier.defaultMinSize(minWidth = 42.dp),

presentation/src/main/java/com/threegap/bitnagil/presentation/home/util/LocalDateExtension.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import java.util.Locale
99

1010
private val koreanLocale = Locale.KOREAN
1111
private val monthYearFormatter = DateTimeFormatter.ofPattern("yyyy년 M월", koreanLocale)
12+
private val executionTimeFormatter12 = DateTimeFormatter.ofPattern("a h:mm", koreanLocale)
1213
private val executionTimeFormatter24 = DateTimeFormatter.ofPattern("HH:mm", koreanLocale)
1314

1415
fun LocalDate.getCurrentWeekDays(): List<LocalDate> =
@@ -23,7 +24,7 @@ fun LocalDate.formatDayOfWeekShort(): String =
2324
fun LocalDate.formatDayOfMonth(): String =
2425
this.dayOfMonth.toString()
2526

26-
fun String.formatExecutionTime(): String =
27+
fun String.formatExecutionTime24Hour(): String =
2728
try {
2829
val time = LocalTime.parse(this)
2930
if (time == LocalTime.MIDNIGHT) {
@@ -34,3 +35,15 @@ fun String.formatExecutionTime(): String =
3435
} catch (e: Exception) {
3536
"시간 미정"
3637
}
38+
39+
fun String.formatExecutionTime12Hour(): String =
40+
try {
41+
val time = LocalTime.parse(this)
42+
if (time == LocalTime.MIDNIGHT) {
43+
"하루종일"
44+
} else {
45+
time.format(executionTimeFormatter12)
46+
}
47+
} catch (e: Exception) {
48+
"시간 미정"
49+
}

presentation/src/main/java/com/threegap/bitnagil/presentation/routinelist/model/RoutineUiModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.threegap.bitnagil.designsystem.R
88
import com.threegap.bitnagil.domain.routine.model.DayOfWeek
99
import com.threegap.bitnagil.domain.routine.model.RecommendedRoutineType
1010
import com.threegap.bitnagil.domain.routine.model.Routine
11+
import com.threegap.bitnagil.presentation.home.util.formatExecutionTime12Hour
1112
import kotlinx.parcelize.Parcelize
1213

1314
@Parcelize
@@ -26,7 +27,7 @@ fun Routine.toUiModel(): RoutineUiModel =
2627
routineId = this.routineId,
2728
routineName = this.routineName,
2829
repeatDay = this.repeatDay,
29-
executionTime = this.formattedExecutionTime,
30+
executionTime = this.executionTime.formatExecutionTime12Hour(),
3031
routineDate = this.routineDate,
3132
subRoutineNames = this.subRoutineNames,
3233
recommendedRoutineType = this.recommendedRoutineType,

0 commit comments

Comments
 (0)