Latest 0.2.0
License MIT
Platforms ios 8.0

Time is an illusion. – Albert Einstein

Hybrid Logical Clocks for iOS.

CI Status


Precise clock synchronization is hard.
For mobile devices, this problem is even worse.
It can be difficult to determine ordering of events when your clocks are out of sync.

This library contains tools to deal with problems related to clock synchronization.

Hybrid Logical Clock (HLC)

Hybrid logical clocks allow causal ordering between events, even when those events are created on multiple devices with differing clocks.


Network Time

Hybrid Logical Clocks are useful when clocks differ slightly.
User controlled mobile devices may have clocks that differ by hours (due to wrong time zone settings, etc), which is outside the bounds of what HLC is designed to compensate for.

A simple option is to maintain an offset based on the Date header received with http responses.
This can be performed e.g. upon initial login so that the clock is synced when the app starts.
This should be sufficient to get the iPad’s clock to within a few seconds of "true time".

Another option is to employ NTP. NHNetworkTime is one NTP implementation that may be used:


import HLClock

// Create a new timestamp
let newTimestamp =

// Update clock when receiving a new message


To run the example project, clone the repo, and run pod install from the Example directory first.


HLClock is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "HLClock"


  • [x] Implement HLC algorithm
  • [x] Make threadsafe using atomic swap
  • [x] Package as library, installable through cocoapods
  • [ ] Clock offset uses moving median
  • [ ] Overflow and overdrift protection
  • [ ] Add hlclock usage to example app
  • [ ] Generate UUIDv1 using HLC timestamp
  • [ ] Add quickcheck tests
  • [ ] Support SPM


HLClock is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "HLClock",
    "version": "0.2.0",
    "summary": "Hybrid Logical Clocks for iOS.",
    "description": "Hybrid Logical Clocks enable causal ordering of events within a distributed system with imperfect clocks.nSee:",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "Stephen Spalding": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.2.0"
    "platforms": {
        "ios": "8.0"
    "source_files": "HLClock/Classes/**/*"

Pin It on Pinterest

Share This