diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt | 15 | ||||
-rw-r--r-- | shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/SpeedUnit.kt | 5 |
2 files changed, 20 insertions, 0 deletions
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt index 133c028..af4e14d 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt @@ -1,6 +1,7 @@ package mx.trackermap.TrackerMap.utils import kotlinx.datetime.* +import kotlin.math.round class Formatter { companion object { @@ -8,5 +9,19 @@ class Formatter { 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" + } + } + } } }
\ No newline at end of file diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/SpeedUnit.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/SpeedUnit.kt new file mode 100644 index 0000000..bc9cdb4 --- /dev/null +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/SpeedUnit.kt @@ -0,0 +1,5 @@ +package mx.trackermap.TrackerMap.utils + +enum class SpeedUnit { + KMH, MPH, KN +}
\ No newline at end of file |