Skip to content

v0.4.4 #45

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

Merged
merged 4 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/spp.protocol/artifact/trace/Trace.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data class Trace(
val traceIds: List<String>,
val partial: Boolean = false,
val segmentId: String? = null,
val meta: Map<String, String> = mutableMapOf()
val meta: MutableMap<String, String> = mutableMapOf()
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ data class TraceSpan(
meta[tag] = value
}

fun putMetaInt(tag: String): Int? {
fun getMetaInt(tag: String): Int? {
return meta[tag]?.toIntOrNull()
}

Expand Down
37 changes: 20 additions & 17 deletions src/commonMain/kotlin/spp.protocol/utils/TimeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,54 @@
*/
package spp.protocol.utils

fun Int.toPrettyDuration(): String {
import kotlin.jvm.JvmOverloads

fun Int.toPrettyDuration(translate: (String)->String = { it }): String {
val days = this / 86400000.0
if (days > 1) {
return "${days.toInt()}dys"
return "${days.toInt()}" + translate("dys")
}
val hours = this / 3600000.0
if (hours > 1) {
return "${hours.toInt()}hrs"
return "${hours.toInt()}" + translate("hrs")
}
val minutes = this / 60000.0
if (minutes > 1) {
return "${minutes.toInt()}mins"
return "${minutes.toInt()}" + translate("mins")
}
val seconds = this / 1000.0
if (seconds > 1) {
return "${seconds.toInt()}secs"
return "${seconds.toInt()}" + translate("secs")
}
return "${this}ms"
return "$this" + translate("ms")
}

fun Double.fromPerSecondToPrettyFrequency(): String {
@JvmOverloads
fun Double.fromPerSecondToPrettyFrequency(translate: (String)->String = { it }): String {
return when {
this > 1000000.0 -> "${this / 1000000.0.toInt()}M/sec"
this > 1000.0 -> "${this / 1000.0.toInt()}K/sec"
this > 1.0 -> "${this.toInt()}/sec"
else -> "${(this * 60.0).toInt()}/min"
this > 1000000.0 -> "${this / 1000000.0.toInt()}M/" + translate("sec")
this > 1000.0 -> "${this / 1000.0.toInt()}K/" + translate("sec")
this > 1.0 -> "${this.toInt()}/" + translate("sec")
else -> "${(this * 60.0).toInt()}/" + translate.invoke("min")
}
}

fun Long.toPrettyDuration(): String {
fun Long.toPrettyDuration(translate: (String)->String = { it }): String {
val days = this / 86400000.0
if (days > 1) {
return "${days.toInt()}d"
return "${days.toInt()}" + translate("dys")
}
val hours = this / 3600000.0
if (hours > 1) {
return "${hours.toInt()}h"
return "${hours.toInt()}" + translate("hrs")
}
val minutes = this / 60000.0
if (minutes > 1) {
return "${minutes.toInt()}m"
return "${minutes.toInt()}" + translate("mins")
}
val seconds = this / 1000.0
if (seconds > 1) {
return "${seconds.toInt()}s"
return "${seconds.toInt()}" + translate("secs")
}
return "${this}ms"
return "$this" + translate("ms")
}