Skip to content

Commit 742ca92

Browse files
committed
Update README for kotlin.time usage
1 parent 2c9519d commit 742ca92

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

README.MD

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@
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/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` instance.
1313
```kotlin
14+
import kotlin.time.Clock
15+
import kotlin.time.Instant
16+
import kotlin.time.Duration
1417
val networkTime: Instant = Clock.Network.now()
1518
val systemTime: Instant = Clock.System.now()
1619
val diff: Duration = networkTime - systemTime
1720
```
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+
1827
### Synchronization
1928
When running the application, it's necessary to synchronize the time with the network using the platform-specific code:
2029
- Android:

0 commit comments

Comments
 (0)