-
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 remote-tracking branch 'origin/develop' into mod/#148-post-api-…
…dto-mod
- Loading branch information
Showing
2 changed files
with
22 additions
and
3 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/spoony/spoony/core/util/extension/StringExt.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,4 +1,22 @@ | ||
package com.spoony.spoony.core.util.extension | ||
|
||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
import java.time.format.DateTimeParseException | ||
import java.util.Locale | ||
|
||
fun String?.toValidHexColor(): String = | ||
if (this != null && Regex("^[0-9A-Fa-f]{6}$").matches(this)) this else "FFFFFF" | ||
|
||
fun String.formatToYearMonthDay(): String? { | ||
return try { | ||
val inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSS", Locale.getDefault()) | ||
val outputFormatter = DateTimeFormatter.ofPattern("yyyy년 M월 d일", Locale.getDefault()) | ||
val dateTime = LocalDateTime.parse(this, inputFormatter) | ||
dateTime.format(outputFormatter) | ||
} catch (e: DateTimeParseException) { | ||
null | ||
} catch (e: Exception) { | ||
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