|
3 | 3 |  |
4 | 4 | [](https://github.com/softartdev/Kronos-Multiplatform/actions/workflows/build_publish.yml) |
5 | 5 |
|
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/kotlin-time/) API and supports the following platforms: |
7 | 7 | - Android |
8 | 8 | - iOS |
9 | 9 | - Desktop JVM (MacOS, Linux, Windows) |
10 | 10 | ## 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` instance. |
13 | 13 | ```kotlin |
| 14 | +import kotlin.time.Clock |
| 15 | +import kotlin.time.Instant |
| 16 | +import kotlin.time.Duration |
14 | 17 | val networkTime: Instant = Clock.Network.now() |
15 | 18 | val systemTime: Instant = Clock.System.now() |
16 | 19 | val diff: Duration = networkTime - systemTime |
17 | 20 | ``` |
| 21 | + |
| 22 | +### `kotlinx-datetime` Deprecation |
| 23 | +Starting from `kotlinx-datetime` **0.7.0**, the `Clock` interface and `Instant` class were moved to the Kotlin standard library as `kotlin.time.Clock` and `kotlin.time.Instant`. The old types are now deprecated. |
| 24 | + |
| 25 | +If your project still relies on them, replace the `kotlinx.datetime.Clock` and `kotlinx.datetime.Instant` imports with the corresponding `kotlin.time` ones. No other code changes are required. |
| 26 | + |
18 | 27 | ### Synchronization |
19 | 28 | When running the application, it's necessary to synchronize the time with the network using the platform-specific code: |
20 | 29 | - Android: |
|
0 commit comments