Use CommonMain for presentation, use Klock date/format library

This commit is contained in:
Syer10
2022-03-16 23:11:16 -04:00
parent a40383879e
commit 2be40fe12a
145 changed files with 270 additions and 74 deletions

View File

@@ -48,6 +48,7 @@ kotlin {
api(libs.multiplatformSettings.coroutines)
api(libs.multiplatformSettings.serialization)
api(libs.locale)
api(libs.klock)
}
}
val commonTest by getting {

View File

@@ -8,4 +8,5 @@ package ca.gosyer.core.io
import okio.FileSystem
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
expect val FileSystem.Companion.SYSTEM: FileSystem

View File

@@ -9,4 +9,5 @@ package ca.gosyer.core.lang
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
expect val Dispatchers.IO: CoroutineDispatcher

View File

@@ -9,3 +9,9 @@ package ca.gosyer.core.lang
import io.fluidsonic.locale.Locale
expect fun Locale.Companion.getDefault(): Locale
expect fun Locale.getDisplayLanguage(displayLocale: Locale): String
expect fun Locale.getDisplayName(displayLocale: Locale): String
expect val Locale.displayName: String

View File

@@ -6,6 +6,8 @@
package ca.gosyer.core.lang
import io.fluidsonic.locale.Locale
/**
* Replaces the given string to have at most [count] characters using [replacement] at its end.
* If [replacement] is longer than [count] an exception will be thrown when `length > count`.
@@ -17,3 +19,9 @@ fun String.chop(count: Int, replacement: String = "…"): String {
this
}
}
expect fun String.uppercase(locale: Locale): String
expect fun String.lowercase(locale: Locale): String
expect fun Char.titlecase(locale: Locale): String

View File

@@ -8,6 +8,15 @@ package ca.gosyer.core.lang
import io.fluidsonic.locale.Locale
import io.fluidsonic.locale.toCommon
import io.fluidsonic.locale.toPlatform
import java.util.Locale as PlatformLocale
actual fun Locale.Companion.getDefault(): Locale = PlatformLocale.getDefault().toCommon()
actual fun Locale.getDisplayLanguage(displayLocale: Locale): String = toPlatform()
.getDisplayLanguage(displayLocale.toPlatform())
actual fun Locale.getDisplayName(displayLocale: Locale): String = toPlatform()
.getDisplayName(displayLocale.toPlatform())
actual val Locale.displayName get() = toPlatform().displayName

View File

@@ -7,7 +7,15 @@
package ca.gosyer.core.lang
import java.util.Locale
import io.fluidsonic.locale.Locale
import io.fluidsonic.locale.toPlatform
fun String.capitalize(locale: Locale = Locale.getDefault()) =
replaceFirstChar { if (it.isLowerCase()) it.titlecase(locale) else it.toString() }
actual fun String.uppercase(locale: Locale): String = uppercase(locale.toPlatform())
actual fun String.lowercase(locale: Locale): String = lowercase(locale.toPlatform())
actual fun Char.titlecase(locale: Locale): String = titlecase(locale.toPlatform())