https://github.com/lemon-mint/webtimesync
Simple Time Sync
https://github.com/lemon-mint/webtimesync
Last synced: 3 months ago
JSON representation
Simple Time Sync
- Host: GitHub
- URL: https://github.com/lemon-mint/webtimesync
- Owner: lemon-mint
- License: unlicense
- Created: 2022-01-01T13:37:21.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-24T04:26:59.000Z (almost 3 years ago)
- Last Synced: 2025-02-20T12:47:37.940Z (4 months ago)
- Language: TypeScript
- Size: 144 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WebTimeSync
A lightweight http-based time synchronization library.
# Server Side
Server returns a simple json response with the timing information.
Server SHOULD process requests in constant time
Response SHOULD be a JSON object with the following keys:
t1: the server time when the request was received (float)
t2: the server time when the response was sent (float)The unit MUST be milliseconds
Example response: `{"t1":1641083722668.4788,"t2":1641083722668.484}`
Reference implementation: [https://github.com/lemon-mint/real-time](https://github.com/lemon-mint/real-time)
## Demo Server
You can use this Demo Server to test your client.
endpoint: [https://time.vlue.dev/time](https://time.vlue.dev/time)
Note: This server is not meant to be used in production.
Disclaimer: The Software is provided "AS IS" without any warranty of any kind, express, implied or otherwise.
time.vlue.dev is synchronized with the [NTP server](https://developers.google.com/time/) (leap-smeared time).
# Client Side
``` javascript
import {
getTime,
syncTime
} from 'webtimesync';async function main() {
// synchronize the time
await syncTime();// get the time
const time = getTime();
console.log(time);// calculate the time difference
console.log(time - new Date().getTime());
}main();
```