Skip to content

Commit d7ae4ce

Browse files
Fix formatted(withColons=true) returns "01:3:9" instead of "01:03:09"
1 parent 1e729da commit d7ae4ce

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/kotlin/KotlinFunctionLibrary.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,15 @@ object KotlinFunctionLibrary{
241241
/**
242242
* Takes a [Triple] of <hour,minute,second> and returns either e.g. "05:32:15", or "5 hr 32 min 15 sec"
243243
* */
244-
fun Triple<Int, Int, Int>.formatted(withColons: Boolean) =
245-
if (withColons) "${if(this.first.toString().length==1) "0${this.first}" else "${this.first}"}:${this.second}:${this.third}"
244+
fun Triple<Int, Int, Int>.formatted(withColons: Boolean): String {
245+
fun Int.formatted() = if (this < 10) "0$this" else this.toString()
246+
return if (withColons) "${this.first.formatted()}:${this.second.formatted()}:${this.third.formatted()}"
246247
else timeFormattedConcisely(
247248
this.first,
248249
this.second,
249250
this.third
250251
)
252+
}
251253

252254
/**
253255
* Takes an hour, minute, and second, and will return a string with only those values which are not equal to 0 (e.g. "5 hr 15 sec", "5 hr 32 min 15 sec")

0 commit comments

Comments
 (0)