Skip to content

Repository files navigation

Kronos Multiplatform Library

Maven CentralBuild & Publish CI/CD

Kotlin Multiplatform library for network time synchronization. It extends the kotlin.time API and supports the following platforms:

  • Android
  • iOS
  • Desktop JVM (MacOS, Linux, Windows)

Usage

kotlin.time Extension

The library extends the main Clock interface from the standard library. You can use the Clock.Network class to retrieve the current network time, similar to using the built-in Clock.System instance.

val networkTime:Instant=Clock.Network.now() // 2025-06-30T13:42:43.712Zval systemTime:Instant=Clock.System.now() // 2025-06-30T13:42:43.566455Zval diff:Duration= networkTime - systemTime // 145.545ms

Synchronization

When running the application, it's necessary to synchronize the time with the network using the platform-specific code:

  • Android:
classApp : Application() {
overridefunonCreate() {
super.onCreate()
Clock.Network.sync(applicationContext)
}
}
  • iOS:
@mainstructiosApp:App{init(){Clock.Network.sync()}varbody:someScene{...}}
  • Desktop JVM:
funmain() {
Clock.Network.sync()
...
}

Installation

The latest release is available on Maven Central.

  1. Add the Maven Central repository if it is not already included:
repositories {
mavenCentral()
}
  1. In multiplatform projects, add the following dependency to the commonMain source set dependencies:
commonMain {
dependencies {
implementation("io.github.softartdev:kronos:$latestVersion")
}
}

Implementation

The main common interface is implemented using the following:

The project is built and tested using the following:

Releases

Packages

Used by

Contributors

Languages