aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt
blob: af4e14de48a3d9331b90d0787f5541bd6720939d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package mx.trackermap.TrackerMap.utils

import kotlinx.datetime.*
import kotlin.math.round

class Formatter {
    companion object {
        fun formatDate(date: String): String {
            return date.substring(0 until date.indexOf('+'))
                .toLocalDateTime().toString().replace('T', ' ')
        }

        fun formatSpeed(speed: Double, unit: SpeedUnit): String {
            return when (unit) {
                SpeedUnit.KMH -> {
                    "${(speed * 1.852).toInt()} km/h"
                }
                SpeedUnit.MPH -> {
                    "${(speed * 1.15078).toInt()} mph"
                }
                SpeedUnit.KN -> {
                    "${speed.toInt()} kn"
                }
            }
        }
    }
}