{"id":22059231,"url":"https://github.com/opentable/hlclock","last_synced_at":"2025-07-24T00:31:41.986Z","repository":{"id":38485417,"uuid":"61167220","full_name":"opentable/HLClock","owner":"opentable","description":"Hybrid Logical Clocks for iOS","archived":true,"fork":false,"pushed_at":"2020-07-04T17:55:24.000Z","size":71,"stargazers_count":22,"open_issues_count":1,"forks_count":2,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-07-04T17:18:24.011Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opentable.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-15T01:15:39.000Z","updated_at":"2024-12-01T05:11:06.000Z","dependencies_parsed_at":"2022-08-20T04:40:51.194Z","dependency_job_id":null,"html_url":"https://github.com/opentable/HLClock","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/opentable/HLClock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2FHLClock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2FHLClock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2FHLClock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2FHLClock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opentable","download_url":"https://codeload.github.com/opentable/HLClock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2FHLClock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266774717,"owners_count":23982246,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-30T17:27:41.475Z","updated_at":"2025-07-24T00:31:41.589Z","avatar_url":"https://github.com/opentable.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HLClock\n\n`Time is an illusion. – Albert Einstein`\n\n![](https://raw.githubusercontent.com/opentable/HLClock/master/HLClock/Assets/time.jpg?raw=true \"HLClock\")\n\nHybrid Logical Clocks for iOS.\n\n[![CI Status](http://img.shields.io/travis/opentable/HLClock.svg?style=flat)](https://travis-ci.org/opentable/HLClock)\n[![Version](https://img.shields.io/cocoapods/v/HLClock.svg?style=flat)](http://cocoapods.org/pods/HLClock)\n[![License](https://img.shields.io/cocoapods/l/HLClock.svg?style=flat)](http://cocoapods.org/pods/HLClock)\n[![Platform](https://img.shields.io/cocoapods/p/HLClock.svg?style=flat)](http://cocoapods.org/pods/HLClock)\n\n\n## Overview\n\nPrecise clock synchronization is hard.\nFor mobile devices, this problem is even worse.\nIt can be difficult to determine ordering of events when your clocks are out of sync.\n\nThis library contains tools to deal with problems related to clock synchronization.\n\n### Hybrid Logical Clock (HLC)\n\nHybrid logical clocks allow causal ordering between events, even when those events are created on multiple devices with differing clocks.\n\nSee: http://muratbuffalo.blogspot.com/2014/07/hybrid-logical-clocks.html\n\n![](http://3.bp.blogspot.com/-akIvKFkOoPA/U9T0IFFDQsI/AAAAAAAABrQ/Bi7YfWAIaDE/s1600/counter2.png?raw=true \"Hybrid Logicl Clock Example\")\n\n### Network Time\n\nHybrid Logical Clocks are useful when clocks differ slightly.\nUser 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.\n\nA simple option is to maintain an offset based on the Date header received with http responses.\nThis can be performed e.g. upon initial login so that the clock is synced when the app starts.\nThis should be sufficient to get the iPad's clock to within a few seconds of \"true time\".\n\nAnother option is to employ NTP. NHNetworkTime is one NTP implementation that may be used: https://github.com/huynguyencong/NHNetworkTime\n\n## Usage\n\n```Swift\nimport HLClock\n\n// Create a new timestamp\nlet newTimestamp = HLClock.global.now()\n\n// Update clock when receiving a new message\nHLClock.global.update(message.timestamp)\n\n```\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Installation\n\nHLClock is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"HLClock\"\n```\n\n## Punchlist\n\n - [x] Implement HLC algorithm\n - [x] Make threadsafe using atomic swap\n - [x] Package as library, installable through cocoapods\n - [ ] Clock offset uses moving median\n - [ ] Overflow and overdrift protection\n - [ ] Add hlclock usage to example app\n - [ ] Generate UUIDv1 using HLC timestamp\n - [ ] Add quickcheck tests\n - [ ] Support SPM\n\n## License\n\nHLClock is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentable%2Fhlclock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopentable%2Fhlclock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentable%2Fhlclock/lists"}