Skip to content

Commit

Permalink
DateParser를 다른 파일로 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
toastmeister1 committed Jan 14, 2024
1 parent 43852c0 commit c6029c3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
37 changes: 37 additions & 0 deletions domain/src/main/java/com/yapp/domain/util/DateParser.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.yapp.domain.util

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import javax.inject.Inject

class DateParser @Inject constructor() {

fun parse(
rawDate: String,
formatter: DateTimeFormatter = DATE_FORMAT_WITH_TIME
): LocalDateTime {
require(rawDate.isNotBlank())

return LocalDateTime.parse(rawDate, formatter)
}

fun format(
date: LocalDateTime,
formatter: DateTimeFormatter = DATE_FORMAT_WITH_TIME
): String {
return formatter.format(date)
}

fun format(
date: LocalDateTime,
format: String
): String {
val formatter = DateTimeFormatter.ofPattern(format)

return formatter.format(date)
}

companion object {
private val DATE_FORMAT_WITH_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
}
}
35 changes: 1 addition & 34 deletions domain/src/main/java/com/yapp/domain/util/DateUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.yapp.domain.util

import java.time.Duration
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import javax.inject.Inject

typealias Minute = Long
Expand Down Expand Up @@ -37,36 +36,4 @@ class DateUtil @Inject constructor() {
): Boolean {
return getElapsedTimeInMinute(target, current) >= 0
}
}

class DateParser @Inject constructor() {

fun parse(
rawDate: String,
formatter: DateTimeFormatter = DATE_FORMAT_WITH_TIME
): LocalDateTime {
require(rawDate.isNotBlank())

return LocalDateTime.parse(rawDate, formatter)
}

fun format(
date: LocalDateTime,
formatter: DateTimeFormatter = DATE_FORMAT_WITH_TIME
): String {
return formatter.format(date)
}

fun format(
date: LocalDateTime,
format: String
): String {
val formatter = DateTimeFormatter.ofPattern(format)

return formatter.format(date)
}

companion object {
private val DATE_FORMAT_WITH_TIME = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
}
}
}

0 comments on commit c6029c3

Please sign in to comment.