GithubHelp home page GithubHelp logo

isabella232 / kronos Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mobilenativefoundation/kronos

0.0 0.0 0.0 136 KB

Elegant NTP date library in Swift

License: Apache License 2.0

Swift 97.84% Ruby 0.99% Makefile 1.17%

kronos's Introduction

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.

ascii-clock

Usage

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
    print(date)
}

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.
}

Installation

Embedded frameworks require a minimum deployment target of iOS 8 or OS X Mavericks (10.9).

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 0.39.0+ is required to build Kronos.

To integrate Kronos into your Xcode project using CocoaPods, specify it in your Podfile:

platform :ios, '8.0'
use_frameworks!

pod 'Kronos'

Then, run the following command:

$ pod install

Swift package manager (experimental)

Swift PM is a tool for managing distribution of source code.

To integrate Kronos into your project using Swift PM use:

$ export SWIFT_EXEC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc
$ swift build

Carthage

Carthage is a decentralized dependency manager for Cocoa. You can install it by following the instructions here.

To integrate Kronos into your project using Carthage, specify it in your Cartfile:

github "lyft/Kronos"

Then, run the following command:

$ carthage update

Looking for Kronos for your Android application? Check out Kronos for Android

License

Kronos is maintained by Lyft and released under the Apache 2.0 license. See LICENSE for details.

kronos's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.