-
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.
Merge pull request #15 from Workout-Study/dev
Dev
- Loading branch information
Showing
5 changed files
with
67 additions
and
9 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
7 changes: 5 additions & 2 deletions
7
src/main/kotlin/com/fitmate/batchservice/dto/certification/FitCertificationResultResponse.kt
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package com.fitmate.batchservice.dto.certification | ||
|
||
import com.fitmate.batchservice.persistence.entity.CertificationStatus | ||
import com.fitmate.batchservice.utils.DateParseUtils | ||
import java.time.Instant | ||
|
||
data class FitCertificationResultResponse( | ||
val fitCertificationId: Long, | ||
val certificationStatus: CertificationStatus, | ||
val createdAt: Instant | ||
) | ||
private val createdAtInstant: Instant | ||
) { | ||
val createdAt: String = DateParseUtils.instantToString(createdAtInstant) | ||
} |
7 changes: 5 additions & 2 deletions
7
src/main/kotlin/com/fitmate/batchservice/dto/penalty/FitPenaltyDetailResponse.kt
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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
package com.fitmate.batchservice.dto.penalty | ||
|
||
import com.fitmate.batchservice.utils.DateParseUtils | ||
import java.time.Instant | ||
|
||
data class FitPenaltyDetailResponse( | ||
val fitPenaltyId: Long, | ||
val fitGroupId: Long, | ||
val userId: Int, | ||
val amount: Int, | ||
val createdAt: Instant | ||
) | ||
private val createdAtInstant: Instant | ||
) { | ||
val createdAt: String = DateParseUtils.instantToString(createdAtInstant) | ||
} |
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
49 changes: 49 additions & 0 deletions
49
src/main/kotlin/com/fitmate/batchservice/utils/DateParseUtils.kt
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,49 @@ | ||
package com.fitmate.batchservice.utils | ||
|
||
import com.fitmate.batchservice.exception.NotExpectResultException | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import java.time.DateTimeException | ||
import java.time.Instant | ||
import java.time.OffsetDateTime | ||
import java.time.ZoneId | ||
import java.time.format.DateTimeFormatter | ||
|
||
class DateParseUtils { | ||
|
||
companion object { | ||
val logger: Logger = LoggerFactory.getLogger(DateParseUtils::class.java) | ||
|
||
const val DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss.SSSSSSXXX" | ||
|
||
fun instantToString(instant: Instant?): String { | ||
instant ?: return "" | ||
|
||
val zonedDateTime = instant.atZone(ZoneId.systemDefault()) | ||
|
||
val formatter = DateTimeFormatter.ofPattern(DEFAULT_FORMAT) | ||
|
||
val formattedDate = zonedDateTime.format(formatter) | ||
|
||
return formattedDate | ||
} | ||
|
||
fun stringToInstant(stringInstantDate: String): Instant { | ||
val formatter = DateTimeFormatter.ofPattern(DEFAULT_FORMAT) | ||
|
||
var result: Instant? = null | ||
|
||
try { | ||
val offsetDateTime = OffsetDateTime.parse(stringInstantDate, formatter) | ||
|
||
result = offsetDateTime.toInstant() | ||
} catch (e: DateTimeException) { | ||
logger.error("string to instant parse exception ", e) | ||
} | ||
|
||
if (result == null) throw NotExpectResultException("string to instant parse result null") | ||
|
||
return result | ||
} | ||
} | ||
} |