aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/Formatter.kt
blob: 878418ec39e76490222786b27bce3f7a5a6af99d (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
28
29
package mx.trackermap.TrackerMap.utils

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

class Formatter {
    companion object {
        fun formatDate(str: String): String {
            val timezone = TimeZone.currentSystemDefault()
            val date = str.toInstant().toLocalDateTime(timezone).toString()
            return date
                .replace('T', ' ').trim('Z')
        }

        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"
                }
            }
        }
    }
}