Skip to content

Commit

Permalink
[refactor/sopt-makers#708] attendance Tㅑme Format 방식 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
t1nm1ksun committed Oct 18, 2024
1 parent b1ea410 commit 3997c11
Showing 1 changed file with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
package org.sopt.official.data.model.attendance

import kotlinx.datetime.LocalDateTime
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.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")
Expand All @@ -50,17 +54,20 @@ data class SoptEventResponse(
@SerialName("attendances")
val attendances: List<AttendanceResponse>
) {

@Serializable
data class AttendanceResponse(
@SerialName("status")
val status: String,
@SerialName("attendedAt")
val attendedAt: String = ""
) {

fun toEntity(index: Int): SoptEvent.Attendance {
val attendedAtTime = if (this.status == "ATTENDANCE") {
LocalDateTime.parse(attendedAt).run {
"${this.hour.toString().padStart(2, '0')}:${this.minute.toString().padStart(2, '0')}"
val localDateTime = LocalDateTime.parse(attendedAt)
timeFormat.format(localDateTime)
}
} else {
"${index + 1}차 출석"
Expand All @@ -74,23 +81,19 @@ data class SoptEventResponse(
}

fun toEntity(): SoptEvent {
val eventDateTime: String = if (startAt != "" && endAt != "") {
val eventDateTime: String = if (startAt.isNotBlank() && endAt.isNotBlank()) {
val startAtDateTime = LocalDateTime.parse(startAt)
val endAtDateTime = LocalDateTime.parse(endAt)

if (startAtDateTime.date == endAtDateTime.date) {
"${startAtDateTime.monthNumber}${startAtDateTime.dayOfMonth}${
startAtDateTime.hour.toString().padStart(2, '0')
}:${startAtDateTime.minute.toString().padStart(2, '0')} - ${
endAtDateTime.hour.toString().padStart(2, '0')
}:${endAtDateTime.minute.toString().padStart(2, '0')}"
"${startAtDateTime.monthNumber}${startAtDateTime.dayOfMonth}" +
"${timeFormat.format(startAtDateTime)} - " +
timeFormat.format(endAtDateTime)
} else {
"${startAtDateTime.monthNumber}${startAtDateTime.dayOfMonth}${
startAtDateTime.hour.toString().padStart(2, '0')
}:${
startAtDateTime.minute.toString().padStart(2, '0')
} - ${endAtDateTime.monthNumber}${endAtDateTime.dayOfMonth}${
endAtDateTime.hour.toString().padStart(2, '0')
}:${endAtDateTime.minute.toString().padStart(2, '0')}"
"${startAtDateTime.monthNumber}${startAtDateTime.dayOfMonth}" +
"${timeFormat.format(startAtDateTime)} - " +
"${endAtDateTime.monthNumber}${endAtDateTime.dayOfMonth}" +
timeFormat.format(endAtDateTime)
}
} else {
""
Expand All @@ -107,4 +110,14 @@ data class SoptEventResponse(
attendances = this.attendances.mapIndexed { index, attendanceResponse -> attendanceResponse.toEntity(index) }
)
}

}

object TimeFormat{
private const val FORMAT_PATTERN = "HH:mm"

@OptIn(FormatStringsInDatetimeFormats::class)
val timeFormat = LocalDateTime.Format {
byUnicodePattern(FORMAT_PATTERN)
}
}

0 comments on commit 3997c11

Please sign in to comment.