Swiftpack.co - MobileNativeFoundation/Kronos as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by MobileNativeFoundation.
MobileNativeFoundation/Kronos 4.2.2
Elegant NTP date library in Swift
⭐️ 631
🕓 37 weeks ago
.package(url: "https://github.com/MobileNativeFoundation/Kronos.git", from: "4.2.2")

Kronos is an NTP client library written in Swift. It supports sub-seconds precision and provides a stable monotonic clock that won't be affected by changes in the clock.

Example app

This is an example app that displays the monotonic Clock.now on the left and the system clock (initially out of date) on the right.



Sync clock using a pool of NTP servers

Calling Clock.sync will fire a bunch of NTP requests to up to 5 of the servers on the given NTP pool (default is time.apple.com). As soon as we get the first response, the given closure is called but the Clock will keep trying to get a more accurate response.

Clock.sync { date, offset in
    // This is the first sync (note that this is the fastest but not the
    // most accurate run

Get an NTP sync'ed date

Clock.now is a monotonic NSDate that won't be affected by clock changes.

NSTimer.scheduledTimerWithTimeInterval(1.0, target: self,
                                       selector: #selector(Example.tick),
                                       userInfo: nil, repeats: true)

@objc func tick() {
    print(Clock.now) // Note that this clock will get more accurate as
                     // more NTP servers respond.



Add Kronos to your Podfile:

pod 'Kronos'

Swift Package Manager

Add Kronos to your Pacakge.swift:

.package(name: "Kronos", url: "https://github.com/MobileNativeFoundation/Kronos.git", .upToNextMajor(from: "TAG")),


Add Kronos to your WORKSPACE:

    name = "Kronos",
    sha256 = "",
    strip_prefix = "Kronos-TAG/",
    url = "https://github.com/MobileNativeFoundation/Kronos/archive/TAG.tar.gz",

Then depend on @Kronos//:Kronos


Check out Kronos for Android


Stars: 631
Last commit: 4 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Update deployment targets
37 weeks ago

This fixes compatibility with new Xcode versions

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics