# webtimesync

> Simple Time Sync

Latest version **1.2.0** (published 2022-01-02) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install webtimesync
pnpm add webtimesync
yarn add webtimesync
bun add webtimesync
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2022-01-02 |
| First published | 2022-01-01 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 20.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | lemon-mint |
| Maintainers | lemon-mint |
| Keywords | time, sync, server, clock, time-sync, synchronization, server-time, time-server |

## Links

- npm: https://www.npmjs.com/package/webtimesync
- Repository: https://github.com/lemon-mint/webtimesync
- Homepage: https://github.com/lemon-mint/webtimesync#readme
- Issues: https://github.com/lemon-mint/webtimesync/issues
- npm.io page: https://npm.io/package/webtimesync

## Dependencies (2)

- [present](https://npm.io/package/present.md) ^1.0.0
- [kalmanjs](https://npm.io/package/kalmanjs.md) ^1.1.0

## Recent versions

- 1.2.0 (latest) — 2022-01-02
- 1.1.1 — 2022-01-02
- 1.1.0 — 2022-01-02
- 1.0.0 — 2022-01-01

## 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();
```

---
_Source: https://npm.io/package/webtimesync · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
