Skip to content

Commit

Permalink
Use the dutch locale whenever we use a locale
Browse files Browse the repository at this point in the history
  • Loading branch information
cristan committed Nov 13, 2024
1 parent a25b1c9 commit 99c4644
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import androidx.test.platform.app.InstrumentationRegistry
import kotlinx.coroutines.runBlocking
import nl.ovfietsbeschikbaarheid.repository.OverviewRepository
import nl.ovfietsbeschikbaarheid.repository.StationRepository
import nl.ovfietsbeschikbaarheid.util.dutchLocale
import org.junit.Test
import java.util.Locale

class LocationsDataTest {

Expand All @@ -24,7 +24,7 @@ class LocationsDataTest {
// Same applies to Utrecht Vaartsche Rijn: this is made at 2016.
println("Station ${it.stationCode} not found for $it")
}
val foundCapacity = capacities[it.locationCode.lowercase(Locale.UK)]
val foundCapacity = capacities[it.locationCode.lowercase(dutchLocale)]
if (foundCapacity == null) {
error("Capacity for ${it.locationCode} not found")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import nl.ovfietsbeschikbaarheid.ext.distanceTo
import nl.ovfietsbeschikbaarheid.model.LocationOverviewModel
import nl.ovfietsbeschikbaarheid.model.LocationOverviewWithDistanceModel
import nl.ovfietsbeschikbaarheid.model.LocationType
import nl.ovfietsbeschikbaarheid.util.dutchLocale
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import kotlin.math.roundToInt

object LocationsMapper {
Expand Down Expand Up @@ -49,9 +51,12 @@ object LocationsMapper {
}

fun withDistance(locations: List<LocationOverviewModel>, currentCoordinates: Coordinates): List<LocationOverviewWithDistanceModel> {
val symbols = DecimalFormatSymbols(dutchLocale)

val kmFormat = DecimalFormat().apply {
minimumFractionDigits = 1
maximumFractionDigits = 1
decimalFormatSymbols = symbols
}
return locations
.sortedBy { it.distanceTo(currentCoordinates) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package nl.ovfietsbeschikbaarheid.repository
import android.content.Context
import com.github.doyaaaaaken.kotlincsv.dsl.csvReader
import nl.ovfietsbeschikbaarheid.R
import java.util.Locale
import nl.ovfietsbeschikbaarheid.util.dutchLocale

class StationRepository(private val context: Context) {
private var cachedStations: Map<String, String>? = null
Expand All @@ -19,7 +19,7 @@ class StationRepository(private val context: Context) {
val stationsStream = context.resources.openRawResource(R.raw.stations_nl_2015_08)
val stations = HashMap<String, String>()
csvReader { delimiter = ';' }.readAll(stationsStream).forEach {
val code = it[1].uppercase(Locale.UK)
val code = it[1].uppercase(dutchLocale)
val stationName = it[3]
stations[code] = stationName
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/nl/ovfietsbeschikbaarheid/util/Locale.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package nl.ovfietsbeschikbaarheid.util

import java.util.Locale

val dutchLocale = Locale("NL", "nl")

0 comments on commit 99c4644

Please sign in to comment.