Clean up date format code in docs (#1299)

This commit is contained in:
stevenyomi 2024-02-16 16:37:30 +00:00 committed by Draff
parent beb88a4d60
commit 0edd4a94c0
1 changed files with 7 additions and 6 deletions

View File

@ -423,15 +423,16 @@ will be cached.
```kotlin ```kotlin
private fun parseDate(dateStr: String): Long { private fun parseDate(dateStr: String): Long {
return runCatching { DATE_FORMATTER.parse(dateStr)?.time } return try {
.getOrNull() ?: 0L dateFormat.parse(dateStr)!!.time
} catch (_: ParseException) {
0L
}
} }
companion object { private val dateFormat by lazy {
private val DATE_FORMATTER by lazy {
SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH) SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH)
} }
}
``` ```
Make sure you make the `SimpleDateFormat` a class constant or variable so it doesn't get Make sure you make the `SimpleDateFormat` a class constant or variable so it doesn't get