From 71976f45c1ceafdc54a7dd5b3db3837c08936d45 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 28 Jan 2023 19:12:10 +0530 Subject: [PATCH] Use DateTimeFormatter to create backup file timestamp. --- .../ui/preferences/BackupRestoreSettings.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/preferences/BackupRestoreSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/BackupRestoreSettings.kt index 0673081e7..fc065ae99 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/BackupRestoreSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/BackupRestoreSettings.kt @@ -12,10 +12,12 @@ import com.github.libretube.ui.base.BasePreferenceFragment import com.github.libretube.ui.dialogs.BackupDialog import com.github.libretube.util.BackupHelper import com.github.libretube.util.ImportHelper -import java.time.LocalDate -import java.time.LocalTime +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter class BackupRestoreSettings : BasePreferenceFragment() { + private val backupDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH:mm:ss") + override val titleResourceId: Int = R.string.backup_restore // backup and restore database @@ -105,7 +107,8 @@ class BackupRestoreSettings : BasePreferenceFragment() { advancesBackup?.setOnPreferenceClickListener { BackupDialog { backupFile = it - createBackupFile.launch(getBackupFileName()) + val timestamp = backupDateTimeFormatter.format(LocalDateTime.now()) + createBackupFile.launch("libretube-backup-$timestamp.json") } .show(childFragmentManager, null) true @@ -117,9 +120,4 @@ class BackupRestoreSettings : BasePreferenceFragment() { true } } - - private fun getBackupFileName(): String { - val time = LocalTime.now().toString().split(".").firstOrNull() - return "libretube-backup-${LocalDate.now()}-$time.json" - } }