Skip to content

Commit

Permalink
Round time down to nearest tenth of second
Browse files Browse the repository at this point in the history
  • Loading branch information
ldeso committed Apr 11, 2024
1 parent 10d910e commit 3d3dc2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Use Kotlin Duration and TimeSource
- Add local tests
- Switch to single-project build
- Round time down to nearest tenth of second
- Add `currentTime` variable to decrease code repetitions
- Rename `CallbackCaller` to `CallbackHandler`
- Use correct default values in `ClockContentPreview`
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/ui/components/BasicTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.LayoutDirection
import kotlin.math.ceil
import kotlin.math.floor
import kotlin.time.Duration
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.milliseconds
Expand All @@ -44,7 +45,7 @@ fun BasicTime(
style: TextStyle = TextStyle.Default,
timeOverColor: Color = style.color,
) {
val time = 100.milliseconds * ceil(timeProvider() / 100.milliseconds)
val time = 100.milliseconds * floor(timeProvider() / 100.milliseconds)
val punctuationStyle = if (time.isPositive()) style else style.merge(color = timeOverColor)
val digitStyle = punctuationStyle.merge(fontFamily = FontFamily.Monospace)
val hoursText: String
Expand All @@ -61,14 +62,14 @@ fun BasicTime(

CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
Row(modifier) {
if (time > 1.hours) {
if (time >= 1.hours) {
BasicText(text = hoursText, style = digitStyle)
BasicText(text = ":", style = punctuationStyle)
}
BasicText(text = minutesText, style = digitStyle)
BasicText(text = ":", style = punctuationStyle)
BasicText(text = secondsText, style = digitStyle)
if (time <= 1.hours) {
if (time < 1.hours) {
BasicText(text = ".", style = punctuationStyle)
BasicText(text = decimalText, style = digitStyle)
}
Expand Down

0 comments on commit 3d3dc2e

Please sign in to comment.