{"id":15047396,"url":"https://github.com/laateef/xclox","last_synced_at":"2026-02-05T05:34:43.045Z","repository":{"id":220794343,"uuid":"752589204","full_name":"Laateef/Xclox","owner":"Laateef","description":"C++11 header-only cross-platform date and time library with an asynchronous NTP client","archived":false,"fork":false,"pushed_at":"2024-03-17T06:20:32.000Z","size":635,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-20T15:59:12.960Z","etag":null,"topics":["asio","async","client","clock","cmake","cpp","cpp11","cross-platform","date","datetime","event-driven","header-only","ntp","ntp-client","packet","query","server","tdd","test-driven-development","time"],"latest_commit_sha":null,"homepage":"https://laateef.github.io/Xclox/index.html","language":"C++","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/Laateef.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-04T09:41:55.000Z","updated_at":"2024-06-04T22:44:16.000Z","dependencies_parsed_at":"2024-03-17T05:27:08.080Z","dependency_job_id":"8028f952-d60a-4957-a862-d6ed4fcf89b2","html_url":"https://github.com/Laateef/Xclox","commit_stats":null,"previous_names":["laateef/xclox"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Laateef%2FXclox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Laateef%2FXclox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Laateef%2FXclox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Laateef%2FXclox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Laateef","download_url":"https://codeload.github.com/Laateef/Xclox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243475328,"owners_count":20296714,"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":["asio","async","client","clock","cmake","cpp","cpp11","cross-platform","date","datetime","event-driven","header-only","ntp","ntp-client","packet","query","server","tdd","test-driven-development","time"],"created_at":"2024-09-24T20:57:43.000Z","updated_at":"2026-02-05T05:34:43.019Z","avatar_url":"https://github.com/Laateef.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Xclox\n\n[![build](https://github.com/Laateef/Xclox/actions/workflows/ci.yml/badge.svg)](https://github.com/Laateef/Xclox/actions)\n[![codecov](https://codecov.io/gh/Laateef/Xclox/graph/badge.svg?token=BRA4UX75XF)](https://codecov.io/gh/Laateef/Xclox)\n[![license](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nA header-only cross-platform date and time library for C++.\n\nIt offers a high-level approach to creating, manipulating, and formatting times, dates, and datetimes.\n\nIt provides a flexible and advanced NTP client for querying internet time in an asynchronous fashion based on the ASIO library.\n\nIt has been thoroughly tested, as its development has been test-driven (TDD).\n\n## Usage\n\nThe following example shows only the basic functionalities of the library. For further details, please see the [documentation](https://laateef.github.io/Xclox/index.html).\n\n### Example\n\n```cpp\n#include \u003ciostream\u003e\n\n#include \u003cxclox.hpp\u003e\n\nusing namespace xclox;\n\nint main(int argc, char** argv)\n{\n    Time t(1, 2, 3);\n    Date d(2003, 2, 1);\n    DateTime dt(d, t);\n\n    std::cout \u003c\u003c \" DateTime: \" \u003c\u003c dt\n              \u003c\u003c \"\\n\\t Time: \" \u003c\u003c d\n              \u003c\u003c \"\\n\\t Date: \" \u003c\u003c t\n              \u003c\u003c \"\\n\\n Epoch: \" \u003c\u003c DateTime::epoch()\n              \u003c\u003c \"\\n\\n Now: \" \u003c\u003c DateTime::current().toString(\"yyyy-MM-dd hh:mm:ss.f\")\n              \u003c\u003c \"\\n\\n Tomorrow: \" \u003c\u003c DateTime(std::chrono::system_clock::now()) + DateTime::Days(1);\n\n    ntp::Client client([\u0026](\n                           const std::string\u0026 name,\n                           const std::string\u0026 address,\n                           ntp::Client::Status status,\n                           const ntp::Packet\u0026 packet,\n                           const std::chrono::steady_clock::duration\u0026 rtt) {\n        const auto\u0026 destinationTime = std::chrono::system_clock::now();\n        std::cout \u003c\u003c \"\\n\\n NTP Client: \"\n                  \u003c\u003c \"\\n\\t Server Name: \" \u003c\u003c name\n                  \u003c\u003c \"\\n\\t Resolved Address: \" \u003c\u003c address\n                  \u003c\u003c \"\\n\\t Query Status: \" \u003c\u003c (status == ntp::Client::Status::Succeeded ? \"Succeeded\" : \"Failed\")\n                  \u003c\u003c \"\\n\\t Packet: \"\n                  \u003c\u003c \"\\n\\t\\t Valid: \" \u003c\u003c std::boolalpha \u003c\u003c !packet.isNull()\n                  \u003c\u003c \"\\n\\t\\t Reference Timestamp: \" \u003c\u003c packet.referenceTimestamp()\n                  \u003c\u003c \"\\n\\t\\t Origin Timestamp: \" \u003c\u003c packet.originTimestamp()\n                  \u003c\u003c \"\\n\\t\\t Receive Timestamp: \" \u003c\u003c packet.originTimestamp()\n                  \u003c\u003c \"\\n\\t\\t Transmit Timestamp: \" \u003c\u003c packet.originTimestamp()\n                  \u003c\u003c \"\\n\\t Destination Time: \" \u003c\u003c DateTime(destinationTime)\n                  \u003c\u003c \"\\n\\t Round-trip Time: \" \u003c\u003c std::chrono::duration_cast\u003cstd::chrono::nanoseconds\u003e(rtt).count() \u003c\u003c \"ns\"\n                  \u003c\u003c \"\\n\\t Time Offset: \" \u003c\u003c std::chrono::duration_cast\u003cstd::chrono::nanoseconds\u003e(packet.offset(destinationTime)).count() \u003c\u003c \"ns\"\n                  \u003c\u003c \"\\n\\t Adjusted Time: \" \u003c\u003c DateTime(destinationTime + packet.offset(destinationTime));\n    });\n\n    client.query(\"pool.ntp.org\");\n\n    return 0;\n}\n```\n\n### Output\n\n```\n DateTime: 2003-02-01T01:02:03.000\n         Time: 2003-02-01\n         Date: 01:02:03.000\n\n Epoch: 1970-01-01T00:00:00.000\n\n Now: 2024-01-29 03:16:56.7\n\n Tomorrow: 2024-01-30T03:16:56.770\n\n NTP Client:\n         Server Name: pool.ntp.org\n         Resolved Address: 162.159.200.1:123\n         Query Status: Succeeded\n         Packet:\n                 Valid: true\n                 Reference Timestamp: 16816888586391356887\n                 Origin Timestamp: 16816888685208543774\n                 Receive Timestamp: 16816888685208543774\n                 Transmit Timestamp: 16816888685208543774\n         Destination Time: 2024-01-29T03:16:56.916\n         Round-trip Time: 83525300ns\n         Time Offset: 360550500ns\n         Adjusted Time: 2024-01-29T03:16:57.276\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaateef%2Fxclox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaateef%2Fxclox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaateef%2Fxclox/lists"}