generated from GSM-MSG/MSG-Repository-Generator
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #206 from GSM-MSG/refactor/#204_update_token_fucti…
…on_logic 🔀 :: (#204) AuthTokenDataSource의 함수 수정
- Loading branch information
Showing
5 changed files
with
93 additions
and
110 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
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
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
26 changes: 21 additions & 5 deletions
26
core/network/src/main/java/com/msg/network/util/DateTimeFormatter.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,18 +1,34 @@ | ||
package com.msg.network.util | ||
|
||
import java.time.Instant | ||
import java.time.LocalDateTime | ||
import java.time.ZoneId | ||
import java.time.format.DateTimeFormatter | ||
import java.time.format.DateTimeParseException | ||
|
||
fun Any?.toLocalDateTime(): LocalDateTime? { | ||
val dateString = this?.toString() | ||
if (dateString != null) { | ||
return try { | ||
LocalDateTime.parse(dateString, DateTimeFormatter.ofPattern("yyyy-MM-d'T'HH:mm:ss")) | ||
return when { | ||
dateString == null -> null | ||
else -> try { | ||
when { | ||
dateString.matches(Regex("\\d{13}")) -> { // Milliseconds -> LocalDateTime 처리 | ||
LocalDateTime.ofInstant(Instant.ofEpochMilli(dateString.toLong()), ZoneId.systemDefault()) | ||
} | ||
dateString.contains('.') -> { // 나노초를 포함한 경우 나노초 제거 | ||
val trimmedDateString = dateString.substring(0, dateString.indexOf('.')) | ||
LocalDateTime.parse(trimmedDateString, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")) | ||
} | ||
else -> { // 나노초를 포함하지 않은 경우 | ||
LocalDateTime.parse(dateString, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")) | ||
} | ||
} | ||
} catch (e: DateTimeParseException) { | ||
e.printStackTrace() | ||
null | ||
} catch (e: NumberFormatException) { | ||
e.printStackTrace() | ||
null | ||
} | ||
} | ||
return null | ||
} | ||
} |
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