Skip to content

Commit

Permalink
Commonize timestamper function to use padStart instead of String.format
Browse files Browse the repository at this point in the history
  • Loading branch information
yuroyami committed Aug 30, 2024
1 parent 4a257c8 commit b8aecf3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ actual fun getDefaultEngine(): String = defaultEngineAndroid

actual fun generateTimestampMillis() = System.currentTimeMillis()

@SuppressLint("DefaultLocale")
actual fun timeStamper(seconds: Number): String {
val secs = seconds.toLong()
return if (secs < 3600) {
String.format("%02d:%02d", (secs / 60) % 60, secs % 60)
} else {
String.format("%02d:%02d:%02d", secs / 3600, (secs / 60) % 60, secs % 60)
}
}
//@SuppressLint("DefaultLocale")
//actual fun timeStamper(seconds: Number): String {
// val secs = seconds.toLong()
// return if (secs < 3600) {
// String.format("%02d:%02d", (secs / 60) % 60, secs % 60)
// } else {
// String.format("%02d:%02d:%02d", secs / 3600, (secs / 60) % 60, secs % 60)
// }
//}

actual fun getFolderName(uri: String): String? {
val childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ expect fun getDefaultEngine(): String
expect fun generateTimestampMillis(): Long

/** Converts seconds into a readable hh:mm:ss format */
expect fun timeStamper(seconds: Number): String
fun timeStamper(seconds: Number): String {
val secs = seconds.toLong()
return if (secs < 3600) {
"${(secs / 60) % 60}:${(secs % 60).toString().padStart(2, '0')}".padStart(5, '0')
} else {
"${secs / 3600}:${((secs / 60) % 60).toString().padStart(2, '0')}:${(secs % 60).toString().padStart(2, '0')}".padStart(8, '0')
}
}

/** Gets the filename based on its URI, needs context on Android */
expect fun getFileName(uri: String): String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import platform.Foundation.NSURL
import platform.Foundation.create
import platform.Foundation.currentLocale
import platform.Foundation.languageCode
import platform.Foundation.lastPathComponent
import platform.Foundation.timeIntervalSince1970
import kotlin.math.roundToInt
import kotlin.math.roundToLong
Expand All @@ -34,14 +33,6 @@ actual fun generateTimestampMillis(): Long {
return (NSDate().timeIntervalSince1970 * 1000).roundToLong()
}

actual fun timeStamper(seconds: Long): String {
return if (seconds < 3600) {
"${(seconds / 60) % 60}:${(seconds % 60).toString().padStart(2, '0')}".padStart(5, '0')
} else {
"${seconds / 3600}:${((seconds / 60) % 60).toString().padStart(2, '0')}:${(seconds % 60).toString().padStart(2, '0')}".padStart(8, '0')
}
}

actual fun getFileName(uri: String): String? {
return NSURL.fileURLWithPath(uri).lastPathComponent
}
Expand Down

0 comments on commit b8aecf3

Please sign in to comment.