Skip to content

Commit 5ec08fd

Browse files
committed
[refactor/#708] timeFormat 변수 -> 패턴을 인자로 받는 함수화
1 parent c0b7fae commit 5ec08fd

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

app/src/main/java/org/sopt/official/data/model/attendance/SoptEventResponse.kt

+18-17
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
package org.sopt.official.data.model.attendance
2626

2727
import kotlinx.datetime.LocalDateTime
28+
import kotlinx.datetime.format.DateTimeFormat
2829
import kotlinx.datetime.format.FormatStringsInDatetimeFormats
2930
import kotlinx.datetime.format.byUnicodePattern
3031
import kotlinx.serialization.SerialName
3132
import kotlinx.serialization.Serializable
32-
import org.sopt.official.data.model.attendance.TimeFormat.timeFormat
33+
import org.sopt.official.data.model.attendance.TimeFormat.getTimeFormat
3334
import org.sopt.official.domain.entity.attendance.AttendanceStatus
3435
import org.sopt.official.domain.entity.attendance.EventType
3536
import org.sopt.official.domain.entity.attendance.SoptEvent
3637

37-
3838
@Serializable
3939
data class SoptEventResponse(
4040
@SerialName("id")
@@ -62,20 +62,20 @@ data class SoptEventResponse(
6262
@SerialName("attendedAt")
6363
val attendedAt: String = ""
6464
) {
65-
6665
fun toEntity(index: Int): SoptEvent.Attendance {
67-
val attendedAtTime = if (this.status == "ATTENDANCE") {
68-
LocalDateTime.parse(attendedAt).run {
69-
val localDateTime = LocalDateTime.parse(attendedAt)
70-
timeFormat.format(localDateTime)
66+
val attendedAtTime =
67+
if (this.status == "ATTENDANCE") {
68+
LocalDateTime.parse(attendedAt).run {
69+
val localDateTime = LocalDateTime.parse(attendedAt)
70+
getTimeFormat().format(localDateTime)
71+
}
72+
} else {
73+
"${index + 1}차 출석"
7174
}
72-
} else {
73-
"${index + 1}차 출석"
74-
}
7575

7676
return SoptEvent.Attendance(
7777
AttendanceStatus.valueOf(this.status),
78-
attendedAtTime
78+
attendedAtTime,
7979
)
8080
}
8181
}
@@ -107,17 +107,18 @@ data class SoptEventResponse(
107107
eventName = this.eventName,
108108
message = this.message,
109109
isAttendancePointAwardedEvent = type == "HAS_ATTENDANCE",
110-
attendances = this.attendances.mapIndexed { index, attendanceResponse -> attendanceResponse.toEntity(index) }
110+
attendances = this.attendances.mapIndexed { index, attendanceResponse -> attendanceResponse.toEntity(index) },
111111
)
112112
}
113-
114113
}
115114

116-
object TimeFormat{
117-
private const val FORMAT_PATTERN = "HH:mm"
115+
object TimeFormat {
116+
private const val DEFAULT_FORMAT_PATTERN = "HH:mm"
118117

119118
@OptIn(FormatStringsInDatetimeFormats::class)
120-
val timeFormat = LocalDateTime.Format {
121-
byUnicodePattern(FORMAT_PATTERN)
119+
fun getTimeFormat(pattern: String = DEFAULT_FORMAT_PATTERN): DateTimeFormat<LocalDateTime> {
120+
return LocalDateTime.Format {
121+
byUnicodePattern(pattern)
122+
}
122123
}
123124
}

0 commit comments

Comments
 (0)