Skip to content

Commit

Permalink
fix: date and time format in backup naming scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Oct 20, 2024
1 parent 9c697b3 commit a9ce517
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 1 addition & 2 deletions app/src/main/java/com/bnyro/contacts/util/BackupHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ object BackupHelper {
) backupNamingScheme = defaultBackupNamingScheme

val backupType = contactsRepository.label.lowercase()
val dateTime = CalendarUtils.getCurrentDateTime()
val (date, time) = dateTime.substring(0, 10) to dateTime.substring(10)
val (date, time) = CalendarUtils.getCurrentDateAndTime()
val extension = if (encryptBackups) "zip" else "vcf"
val fileName = backupNamingScheme.replace("%s", backupType)
.replace("%d", date)
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/bnyro/contacts/util/CalendarUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ object CalendarUtils {
@SuppressLint("SimpleDateFormat")
val isoDateFormat = SimpleDateFormat("yyyy-MM-dd")

@SuppressLint("SimpleDateFormat")
val isoTimeFormat = SimpleDateFormat("HH:mm:ss")

@SuppressLint("SimpleDateFormat")
val isoDateFormatWithoutYear = SimpleDateFormat("MM-dd")

@SuppressLint("SimpleDateFormat")
val isoTimeFormat = SimpleDateFormat("yyyy-MM-dd-HH:mm:ss")
val isoDateTimeFormat = SimpleDateFormat("yyyy-MM-dd-HH:mm:ss")
private val localizedFormat get() = DateFormat.getDateInstance()

fun millisToDate(milliSeconds: Long, formatter: DateFormat = localizedFormat): String {
Expand Down Expand Up @@ -46,6 +49,12 @@ object CalendarUtils {

fun getCurrentDateTime(): String {
val calendar = Calendar.getInstance()
return isoTimeFormat.format(calendar.time)
return isoDateTimeFormat.format(calendar.time)
}

fun getCurrentDateAndTime(): Pair<String, String> {
val calendar = Calendar.getInstance()

return isoDateFormat.format(calendar.time) to isoTimeFormat.format(calendar.time)
}
}

0 comments on commit a9ce517

Please sign in to comment.