Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify prettyDuration function #35

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions src/main/kotlin/com/featurevisor/testRunner/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonElement
import java.io.File
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.math.abs


internal const val tick = "\u2713"
Expand Down Expand Up @@ -70,14 +70,39 @@ internal fun getRootProjectDir(): String {
throw IllegalStateException("Root project directory not found.")
}

fun prettyDuration(timestamp: Long): String {
val millis = timestamp % 1000
val seconds = TimeUnit.MILLISECONDS.toSeconds(timestamp)
return if (seconds == 0L) {
"$millis ms"
} else {
"$seconds s $millis ms"
fun prettyDuration(diffInMs: Long): String {
var diff = abs(diffInMs)

if (diff == 0L) {
return "0ms"
}

val ms = diff % 1000
diff = (diff - ms) / 1000
val secs = diff % 60
diff = (diff - secs) / 60
val mins = diff % 60
val hrs = (diff - mins) / 60

var result = ""

if (hrs != 0L) {
result += " $hrs h"
}

if (mins != 0L) {
result += " $mins m"
}

if (secs != 0L) {
result += " $secs s"
}

if (ms != 0L) {
result += " $ms ms"
}

return result.trim()
}

internal fun printTestResult(testResult: TestResult) {
Expand Down
Loading