Simplify ReadableTime.getFilenamableTime

This commit is contained in:
FooIbar committed 2024-06-02 22:51:58 +08:00
1 parent 2101ea7a36
commit bc75156232
5 files changed
+8 -8

No files matched your search

@@ -86,7 +86,7 @@ private const val REQUEST_INTERVAL = 5000L
fun Either<String, ByteBuffer>.saveParseError(e: Throwable) {
val dir = AppConfig.externalParseErrorDir ?: return
val file = File(dir, ReadableTime.getFilenamableTime(System.currentTimeMillis()) + ".txt")
val file = File(dir, ReadableTime.getFilenamableTime() + ".txt")
file.sink().buffer().use { sink ->
with(sink) {
writeUtf8(e.message + "\n")
@@ -51,7 +51,6 @@ import eu.kanade.tachiyomi.util.lang.withUIContext
import java.io.File
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.datetime.Clock
import moe.tarsin.coroutines.runSuspendCatching
private const val REPO_URL = "https://github.com/${BuildConfig.REPO_NAME}"
@@ -154,7 +153,7 @@ suspend fun DialogState.showNewVersion(context: Context, release: Release) {
}
}
if (Settings.backupBeforeUpdate) {
val time = ReadableTime.getFilenamableTime(Clock.System.now().toEpochMilliseconds())
val time = ReadableTime.getFilenamableTime()
downloadLocation.createFile("$time.db")?.let {
EhDB.exportDB(context, it)
}
@@ -108,7 +108,7 @@ fun AdvancedScreen(navigator: DestinationsNavigator) {
title = stringResource(id = R.string.settings_advanced_dump_logcat),
summary = stringResource(id = R.string.settings_advanced_dump_logcat_summary),
contract = ActivityResultContracts.CreateDocument("application/zip"),
key = "log-" + ReadableTime.getFilenamableTime(System.currentTimeMillis()) + ".zip",
key = "log-" + ReadableTime.getFilenamableTime() + ".zip",
) { uri ->
uri?.run {
context.runCatching {
@@ -124,7 +124,7 @@ fun AdvancedScreen(navigator: DestinationsNavigator) {
zipOs.putNextEntry(entry)
file.inputStream().use { it.copyTo(zipOs) }
}
val logcatEntry = ZipEntry("logcat-" + ReadableTime.getFilenamableTime(System.currentTimeMillis()) + ".txt")
val logcatEntry = ZipEntry("logcat-" + ReadableTime.getFilenamableTime() + ".txt")
zipOs.putNextEntry(logcatEntry)
Crash.collectInfo(zipOs.writer())
Runtime.getRuntime().exec("logcat -d").inputStream.use { it.copyTo(zipOs) }
@@ -180,7 +180,7 @@ fun AdvancedScreen(navigator: DestinationsNavigator) {
}
}
val exportFailed = stringResource(id = R.string.settings_advanced_export_data_failed)
val now = ReadableTime.getFilenamableTime(System.currentTimeMillis())
val now = ReadableTime.getFilenamableTime()
LauncherPreference(
title = stringResource(id = R.string.settings_advanced_export_data),
summary = stringResource(id = R.string.settings_advanced_export_data_summary),
@@ -62,7 +62,7 @@ object Crash {
fun saveCrashLog(t: Throwable) {
val dir = AppConfig.externalCrashDir ?: return
val nowString = ReadableTime.getFilenamableTime(System.currentTimeMillis())
val nowString = ReadableTime.getFilenamableTime()
val fileName = "crash-$nowString.log"
val file = File(dir, fileName)
runCatching {
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.util
import com.hippo.ehviewer.R
import java.util.Locale
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
@@ -157,6 +158,6 @@ object ReadableTime {
}
}
fun getFilenamableTime(time: Long): String =
fun getFilenamableTime(time: Instant = Clock.System.now()): String =
FILENAMABLE_DATE_FORMAT.format(time.toLocalDateTime(TimeZone.currentSystemDefault()))
}