https://github.com/jcoreio/get-remote-time-offset
algorithm to get the offset between local and remote time, using your function to fetch remote
https://github.com/jcoreio/get-remote-time-offset
Last synced: about 1 year ago
JSON representation
algorithm to get the offset between local and remote time, using your function to fetch remote
- Host: GitHub
- URL: https://github.com/jcoreio/get-remote-time-offset
- Owner: jcoreio
- License: mit
- Created: 2018-10-03T20:20:41.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-02-29T21:54:30.000Z (over 2 years ago)
- Last Synced: 2025-02-01T01:41:50.314Z (over 1 year ago)
- Language: TypeScript
- Size: 401 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# get-remote-time-offset
[](https://travis-ci.org/jcoreio/get-remote-time-offset)
[](https://codecov.io/gh/jcoreio/get-remote-time-offset)
[](https://github.com/semantic-release/semantic-release)
[](http://commitizen.github.io/cz-cli/)
algorithm to get the offset between local and remote time, using your function to fetch remote time
# Installation
```sh
npm install --save @jcoreio/get-remote-time-offset
```
# API
## `getRemoteTimeOffset(fetchRemoteTime, [options])`
```js
import { getRemoteTimeOffset } from '@jcoreio/get-remote-time-offset'
```
### `fetchRemoteTime: () => Promise`
Your function that fetches the time on a remote server by any means you choose
(for instance making an HTTP request) and resolves to the remove server's local
time when it handled the request.
### `options?: ?Object`
Options to customize parameters
### `options.numQueries?: ?number` (default: `5`)
The number of times to fetch remote time before computing the offset
### `options.timeBetweenQueries?: ?number` (default: `10`)
The time to way between queries, in milliseconds
### `options.maxRejections?: ?number` (default: `0`)
The number of rejected promises from `getRemoteTimeOffset` to allow before
rejecting
### `options.timeout?: ?number` (default: `numQueries * timeBetweenQueries * 10`)
The maximum amount of time to run before rejecting
### Returns (`Promise`)
A `Promise` that resolves to the remote time offset, in milliseconds.
Adding this number to the local time will give you the approximate remote time.