Skip to content

Commit 068d69e

Browse files
committed
Remove kotlinx-datetime dependency, update README
1 parent 2c9519d commit 068d69e

File tree

4 files changed

+7
-15
lines changed

4 files changed

+7
-15
lines changed

README.MD

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
![Maven Central](https://img.shields.io/maven-central/v/io.github.softartdev/kronos)
44
[![Build & Publish CI/CD](https://github.com/softartdev/Kronos-Multiplatform/actions/workflows/build_publish.yml/badge.svg)](https://github.com/softartdev/Kronos-Multiplatform/actions/workflows/build_publish.yml)
55

6-
Kotlin Multiplatform library for network time synchronization. It is an extension for the [kotlinx-datetime](https://github.com/Kotlin/kotlinx-datetime) library and supports the following platforms:
6+
Kotlin Multiplatform library for network time synchronization. It extends the [`kotlin.time`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.time/) API and supports the following platforms:
77
- Android
88
- iOS
99
- Desktop JVM (MacOS, Linux, Windows)
1010
## Usage
11-
### kotlinx-datetime Extension
12-
The library [extends the main `Clock` interface](https://github.com/softartdev/Kronos-Multiplatform/blob/main/kronos/src/commonMain/kotlin/com/softartdev/kronos/ClockExt.kt) of the kotlinx-library. You can use the [Clock.Network](https://github.com/softartdev/Kronos-Multiplatform/blob/main/kronos/src/commonMain/kotlin/com/softartdev/kronos/NetworkClock.kt) class to retrieve the current network time, similar to using the built-in [Clock.System](https://github.com/Kotlin/kotlinx-datetime/blob/master/core/common/src/Clock.kt) instance.
11+
### `kotlin.time` Extension
12+
The library [extends the main `Clock` interface](https://github.com/softartdev/Kronos-Multiplatform/blob/main/kronos/src/commonMain/kotlin/com/softartdev/kronos/ClockExt.kt) from the standard library. You can use the [Clock.Network](https://github.com/softartdev/Kronos-Multiplatform/blob/main/kronos/src/commonMain/kotlin/com/softartdev/kronos/NetworkClock.kt) class to retrieve the current network time, similar to using the built-in [`Clock.System`](https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/kotlin/time/Clock.kt#L60) instance.
1313
```kotlin
14-
val networkTime: Instant = Clock.Network.now()
15-
val systemTime: Instant = Clock.System.now()
16-
val diff: Duration = networkTime - systemTime
14+
val networkTime: Instant = Clock.Network.now() // 2025-06-30T13:42:43.712Z
15+
val systemTime: Instant = Clock.System.now() // 2025-06-30T13:42:43.566455Z
16+
val diff: Duration = networkTime - systemTime // 145.545ms
1717
```
1818
### Synchronization
1919
When running the application, it's necessary to synchronize the time with the network using the platform-specific code:

gradle/libs.versions.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ androidx-test = "1.6.1"
1313
compose-uitooling = "1.8.3"
1414
napier = "2.7.1"
1515
kotlinx-coroutines = "1.10.2"
16-
kotlinx-datetime = "0.7.0"
1716
swift-klib = "0.6.4"
1817

1918
[libraries]
@@ -28,7 +27,6 @@ napier = { module = "io.github.aakira:napier", version.ref = "napier" }
2827
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
2928
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" }
3029
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
31-
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" }
3230

3331
[plugins]
3432
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }

kronos/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ kotlin {
2929
sourceSets {
3030
val commonMain by getting {
3131
dependencies {
32-
api(libs.kotlinx.datetime)
3332
}
3433
}
3534
val commonTest by getting {

sampleApp/src/commonMain/kotlin/com/softartdev/kronos/sample/TickScreen.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ import com.softartdev.kronos.Network
3333
import io.github.aakira.napier.Napier
3434
import kotlinx.coroutines.delay
3535
import kotlinx.coroutines.launch
36-
import kotlinx.datetime.TimeZone
37-
import kotlinx.datetime.toLocalDateTime
3836
import kotlin.time.Clock
3937
import kotlin.time.Duration
4038
import kotlin.time.Duration.Companion.seconds
@@ -61,10 +59,7 @@ fun TickScreen() = Scaffold(
6159
Text(text = networkTime.toString(), style = typography.body1)
6260
var systemTime: Instant by remember { mutableStateOf(Clock.System.now()) }
6361
Text(text = "System time:", style = typography.subtitle2)
64-
Text(
65-
text = systemTime.toLocalDateTime(TimeZone.currentSystemDefault()).toString(),
66-
style = typography.body1
67-
)
62+
Text(text = systemTime.toString(), style = typography.body1)
6863
var diff: Duration? by remember {
6964
mutableStateOf(value = networkTime?.let { it - systemTime })
7065
}

0 commit comments

Comments
 (0)