Skip to content

Commit

Permalink
Display hours of play time only if game lasts more than one hour
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Jan 28, 2024
1 parent 41ee456 commit a665d10
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Move the popup messages of the main screen to the absolute bottom of the screen, now covering the
bottom app bar. Avoids covering the bottom row of number buttons when checking if there are errors.
- Mark 'Fast Finishing Mode' as stable.
- Show hours of play time only if the game lasts longer than one hour.

### Deprecated

Expand Down
6 changes: 5 additions & 1 deletion gauguin-core/src/main/kotlin/org/piepmeyer/gauguin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import kotlin.time.Duration
object Utils {
fun displayableGameDuration(gameDuration: Duration): String {
return gameDuration.toComponents { hours, minutes, seconds, _ ->
String.format("%02d:%02d:%02d", hours, minutes, seconds)
if (hours == 0L) {
String.format("%02d:%02d", minutes, seconds)
} else {
String.format("%d:%02d:%02d", hours, minutes, seconds)
}
}
}
}
30 changes: 30 additions & 0 deletions gauguin-core/src/test/kotlin/org/piepmeyer/gauguin/UtilsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.piepmeyer.gauguin

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds

class UtilsTest : FunSpec({

test("duration of zero shows minutes and seconds") {
Utils.displayableGameDuration(0.minutes) shouldBe "00:00"
}

test("duration of 61 seconds shows 1:01") {
Utils.displayableGameDuration(61.seconds) shouldBe "01:01"
}

test("duration less than one hour does not contain hour component") {
Utils.displayableGameDuration(50.minutes) shouldBe "50:00"
}

test("duration with more than one hour does contain hour component") {
Utils.displayableGameDuration(90.minutes) shouldBe "1:30:00"
}

test("duration with two-digit hours does contain two-digit hour component") {
Utils.displayableGameDuration(23.hours) shouldBe "23:00:00"
}
})

0 comments on commit a665d10

Please sign in to comment.