Skip to content

Commit 1fc19eb

Browse files
authored
Merge pull request #45 from sourceplusplus/dev
v0.4.4
2 parents e568129 + 9081e0d commit 1fc19eb

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

src/commonMain/kotlin/spp.protocol/artifact/trace/Trace.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ data class Trace(
3838
val traceIds: List<String>,
3939
val partial: Boolean = false,
4040
val segmentId: String? = null,
41-
val meta: Map<String, String> = mutableMapOf()
41+
val meta: MutableMap<String, String> = mutableMapOf()
4242
) {
4343
override fun equals(other: Any?): Boolean {
4444
if (this === other) return true

src/commonMain/kotlin/spp.protocol/artifact/trace/TraceSpan.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ data class TraceSpan(
7070
meta[tag] = value
7171
}
7272

73-
fun putMetaInt(tag: String): Int? {
73+
fun getMetaInt(tag: String): Int? {
7474
return meta[tag]?.toIntOrNull()
7575
}
7676

src/commonMain/kotlin/spp.protocol/utils/TimeUtils.kt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,54 @@
1717
*/
1818
package spp.protocol.utils
1919

20-
fun Int.toPrettyDuration(): String {
20+
import kotlin.jvm.JvmOverloads
21+
22+
fun Int.toPrettyDuration(translate: (String)->String = { it }): String {
2123
val days = this / 86400000.0
2224
if (days > 1) {
23-
return "${days.toInt()}dys"
25+
return "${days.toInt()}" + translate("dys")
2426
}
2527
val hours = this / 3600000.0
2628
if (hours > 1) {
27-
return "${hours.toInt()}hrs"
29+
return "${hours.toInt()}" + translate("hrs")
2830
}
2931
val minutes = this / 60000.0
3032
if (minutes > 1) {
31-
return "${minutes.toInt()}mins"
33+
return "${minutes.toInt()}" + translate("mins")
3234
}
3335
val seconds = this / 1000.0
3436
if (seconds > 1) {
35-
return "${seconds.toInt()}secs"
37+
return "${seconds.toInt()}" + translate("secs")
3638
}
37-
return "${this}ms"
39+
return "$this" + translate("ms")
3840
}
3941

40-
fun Double.fromPerSecondToPrettyFrequency(): String {
42+
@JvmOverloads
43+
fun Double.fromPerSecondToPrettyFrequency(translate: (String)->String = { it }): String {
4144
return when {
42-
this > 1000000.0 -> "${this / 1000000.0.toInt()}M/sec"
43-
this > 1000.0 -> "${this / 1000.0.toInt()}K/sec"
44-
this > 1.0 -> "${this.toInt()}/sec"
45-
else -> "${(this * 60.0).toInt()}/min"
45+
this > 1000000.0 -> "${this / 1000000.0.toInt()}M/" + translate("sec")
46+
this > 1000.0 -> "${this / 1000.0.toInt()}K/" + translate("sec")
47+
this > 1.0 -> "${this.toInt()}/" + translate("sec")
48+
else -> "${(this * 60.0).toInt()}/" + translate.invoke("min")
4649
}
4750
}
4851

49-
fun Long.toPrettyDuration(): String {
52+
fun Long.toPrettyDuration(translate: (String)->String = { it }): String {
5053
val days = this / 86400000.0
5154
if (days > 1) {
52-
return "${days.toInt()}d"
55+
return "${days.toInt()}" + translate("dys")
5356
}
5457
val hours = this / 3600000.0
5558
if (hours > 1) {
56-
return "${hours.toInt()}h"
59+
return "${hours.toInt()}" + translate("hrs")
5760
}
5861
val minutes = this / 60000.0
5962
if (minutes > 1) {
60-
return "${minutes.toInt()}m"
63+
return "${minutes.toInt()}" + translate("mins")
6164
}
6265
val seconds = this / 1000.0
6366
if (seconds > 1) {
64-
return "${seconds.toInt()}s"
67+
return "${seconds.toInt()}" + translate("secs")
6568
}
66-
return "${this}ms"
69+
return "$this" + translate("ms")
6770
}

0 commit comments

Comments
 (0)