{"id":25874652,"url":"https://github.com/lyft/kronos-android","last_synced_at":"2025-04-07T13:07:19.206Z","repository":{"id":44171847,"uuid":"175689679","full_name":"lyft/Kronos-Android","owner":"lyft","description":"An Open Source Kotlin SNTP library","archived":false,"fork":false,"pushed_at":"2023-03-20T01:58:56.000Z","size":266,"stargazers_count":264,"open_issues_count":13,"forks_count":19,"subscribers_count":388,"default_branch":"master","last_synced_at":"2025-03-31T12:04:32.502Z","etag":null,"topics":["lyft"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lyft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-14T19:52:28.000Z","updated_at":"2025-03-11T12:59:07.000Z","dependencies_parsed_at":"2025-03-02T09:38:46.395Z","dependency_job_id":null,"html_url":"https://github.com/lyft/Kronos-Android","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lyft%2FKronos-Android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lyft%2FKronos-Android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lyft%2FKronos-Android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lyft%2FKronos-Android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lyft","download_url":"https://codeload.github.com/lyft/Kronos-Android/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657281,"owners_count":20974345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lyft"],"created_at":"2025-03-02T09:28:38.428Z","updated_at":"2025-04-07T13:07:19.168Z","avatar_url":"https://github.com/lyft.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kronos-Android\nSynchronized Time Android Library\n\nKronos is an open source Network Time Protocol (NTP) synchronization library for providing a trusted clock on the JVM.\n\nUnlike the device clock, the time reported by Kronos is unaffected when the local time is changed while your app is running. Instead, Kronos stores _accurate time_ along with a delta between the NTP time and the system uptime. Since uptime increases monotonically, Kronos isn't affected by device time changes.\nAccessing `KronosClock.getCurrentTimeMs()` will return the local time based on the last known _accurate time + delta since last sync_.\n\nIntroduction\n------------\n\nInclude the following in your build.gradle file:\n```groovy\nimplementation \"com.lyft.kronos:kronos-android:$latest_version\"\n```\n\nObtain a Kronos clock that is synchronized with NTP servers.\n\n```kotlin\nclass YourApplication : Application() {\n    \n    lateinit var kronosClock: KronosClock\n    \n    override fun onCreate() {\n        super.onCreate()\n        \n        kronosClock = AndroidClockFactory.createKronosClock(applicationContext)\n        kronosClock.syncInBackground()\n    }\n}\n```\n\nReplace usages of \n\n\n```java\nSystem.currentTimeMillis()\n```\n\nwith\n\n\n```java\nkronosClock.getCurrentTimeMs()\n```\n\nIf the NTP server cannot be reached or Kronos has not yet been synced, `getCurrentTimeMs()` will return time from the fallback clock and trigger `syncInBackground()`. If you'd rather control the fallback, you can use `getCurrentNtpTimeMs()`, which returns `null` instead of falling back. \nTo get metadata with an individual timestamp, use `KronosClock.getCurrentTime()`, which returns an instance of `KronosTime`. `KronosTime` contains the `currentTime` and the `timeSinceLastNtpSyncMs`, which will be `null` if `currentTime` is coming from the device clock.\n\nSince it relies on system uptime, Kronos detects and requires a new sync after each reboot. \n\nCustomization\n-------------\n\nKronos comes with a set of reasonable default configurations. You can customize the configuration by using `AndroidClockFactory.createKronosClock` with the following optional parameters:\n\n* `syncListener` \n    * Allows you to log sync operation successes and errors, which maybe useful for custom analytics. Pass an implementation of `SyncListener`.\n* `ntpHosts`\n    * Specify a list of NTP servers with which to sync. Default servers are set to [the NTP pool](https://www.ntppool.org/en/use.html).\n* `requestTimeoutMs`\n    * Lengthen or shorten the timeout value. If the NTP server fails to respond within the given time, the next server will be contacted. If none of the server respond within the given time, the sync operation will be considered a failure.\n* `minWaitTimeBetweenSyncMs`\n    * Kronos attempts a synchronization at most once a minute. If you want to change the frequency, supply the desired interval in milliseconds. Note that you should also supply a `cacheExpirationMs` value. For example, if you shorten the `minWaitTimeBetweenSyncMs` to 30 seconds, but leave the `cacheExpirationMs` to 1 minute, it will have no affect because the cache is still valid within the 1 minute window.\n* `cacheExpirationMs`\n    * Kronos will perform a background sync if the cache is stale. The cache is valid for 1 minute by default. It is simpliest to keep the `cacheExpirationMs` value the same as `minWaitTimeBetweenSyncMs` value.\n                     \n\nWith or without Android\n--------\nFor usage with non-Android modules, Kronos provides access to the Kotlin-only base library called Kronos-Java, which depends on an externally provided local clock and a cache. The Android library simply abstracts away the creation of the clock and cache by extracting the Android system clock from a provided Context and creating its own cache using SharedPreferences.\n\nTo use Kronos-Java include the following in your build.gradle file:\n\n```groovy\nimplementation \"com.lyft.kronos:kronos-java:$latest_version\"\n```\n\n\nVersion infromation are listed under [releases](https://github.com/lyft/Kronos-Android/releases)\n\nLooking for Kronos for your iOS application? Check out [Kronos for iOS](https://github.com/lyft/Kronos)\n\n\nLicense\n-------\n\n    Copyright (C) 2018 Lyft Inc.\n    \n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n    \n        http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n    \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flyft%2Fkronos-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flyft%2Fkronos-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flyft%2Fkronos-android/lists"}