From 5ec08fdbfd37a433e27ad5b09569b75d5fe3e3b2 Mon Sep 17 00:00:00 2001 From: t1nm1ksun Date: Fri, 18 Oct 2024 20:33:57 +0900 Subject: [PATCH] =?UTF-8?q?[refactor/#708]=20timeFormat=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=20->=20=ED=8C=A8=ED=84=B4=EC=9D=84=20=EC=9D=B8?= =?UTF-8?q?=EC=9E=90=EB=A1=9C=20=EB=B0=9B=EB=8A=94=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/attendance/SoptEventResponse.kt | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/sopt/official/data/model/attendance/SoptEventResponse.kt b/app/src/main/java/org/sopt/official/data/model/attendance/SoptEventResponse.kt index 1b1bb7506..c9bb7c6a7 100644 --- a/app/src/main/java/org/sopt/official/data/model/attendance/SoptEventResponse.kt +++ b/app/src/main/java/org/sopt/official/data/model/attendance/SoptEventResponse.kt @@ -25,16 +25,16 @@ package org.sopt.official.data.model.attendance import kotlinx.datetime.LocalDateTime +import kotlinx.datetime.format.DateTimeFormat import kotlinx.datetime.format.FormatStringsInDatetimeFormats import kotlinx.datetime.format.byUnicodePattern import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import org.sopt.official.data.model.attendance.TimeFormat.timeFormat +import org.sopt.official.data.model.attendance.TimeFormat.getTimeFormat import org.sopt.official.domain.entity.attendance.AttendanceStatus import org.sopt.official.domain.entity.attendance.EventType import org.sopt.official.domain.entity.attendance.SoptEvent - @Serializable data class SoptEventResponse( @SerialName("id") @@ -62,20 +62,20 @@ data class SoptEventResponse( @SerialName("attendedAt") val attendedAt: String = "" ) { - fun toEntity(index: Int): SoptEvent.Attendance { - val attendedAtTime = if (this.status == "ATTENDANCE") { - LocalDateTime.parse(attendedAt).run { - val localDateTime = LocalDateTime.parse(attendedAt) - timeFormat.format(localDateTime) + val attendedAtTime = + if (this.status == "ATTENDANCE") { + LocalDateTime.parse(attendedAt).run { + val localDateTime = LocalDateTime.parse(attendedAt) + getTimeFormat().format(localDateTime) + } + } else { + "${index + 1}차 출석" } - } else { - "${index + 1}차 출석" - } return SoptEvent.Attendance( AttendanceStatus.valueOf(this.status), - attendedAtTime + attendedAtTime, ) } } @@ -107,17 +107,18 @@ data class SoptEventResponse( eventName = this.eventName, message = this.message, isAttendancePointAwardedEvent = type == "HAS_ATTENDANCE", - attendances = this.attendances.mapIndexed { index, attendanceResponse -> attendanceResponse.toEntity(index) } + attendances = this.attendances.mapIndexed { index, attendanceResponse -> attendanceResponse.toEntity(index) }, ) } - } -object TimeFormat{ - private const val FORMAT_PATTERN = "HH:mm" +object TimeFormat { + private const val DEFAULT_FORMAT_PATTERN = "HH:mm" @OptIn(FormatStringsInDatetimeFormats::class) - val timeFormat = LocalDateTime.Format { - byUnicodePattern(FORMAT_PATTERN) + fun getTimeFormat(pattern: String = DEFAULT_FORMAT_PATTERN): DateTimeFormat { + return LocalDateTime.Format { + byUnicodePattern(pattern) + } } }