-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43852c0
commit c6029c3
Showing
2 changed files
with
38 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters