# approximate-now

> Approximate (fast) current UNIX time.

Latest version **1.0.2** (published 2021-01-12) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install approximate-now
pnpm add approximate-now
yarn add approximate-now
bun add approximate-now
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-01-12 |
| First published | 2020-12-25 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10.0 |
| Dependencies | 0 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | Gajus Kuizinas |
| Maintainers | gajus |
| Keywords | log, logger, json |

## Links

- npm: https://www.npmjs.com/package/approximate-now
- Repository: https://github.com/gajus/approximate-now
- Homepage: https://github.com/gajus/approximate-now#readme
- Issues: https://github.com/gajus/approximate-now/issues
- npm.io page: https://npm.io/package/approximate-now

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.2 (latest) — 2021-01-12
- 1.0.1 — 2020-12-26
- 1.0.0 — 2020-12-25

## README

# approximate-now

[![Travis build status](http://img.shields.io/travis/gajus/approximate-now/master.svg?style=flat-square)](https://travis-ci.org/gajus/approximate-now)
[![Coveralls](https://img.shields.io/coveralls/gajus/approximate-now.svg?style=flat-square)](https://coveralls.io/github/gajus/approximate-now)
[![NPM version](http://img.shields.io/npm/v/approximate-now.svg?style=flat-square)](https://www.npmjs.org/package/approximate-now)
[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social&label=Follow)](https://twitter.com/kuizinas)

Approximate (fast) current UNIX time.

## Motivation

Sometimes you don't care about the exact time the event took place, but rather need to know approximately when. If your use case is performance sensitive, then `Date.now()` might not be the best option because it has a [measurable impact](#benchmark) to the performance. `approximate-now` provides an approximate (to the error of 50ms) time without a performance penalty of `Date.now()`.

## Usage

```js
import {
  approximateTime,
} from 'approximate-now';

// `approximateTime.now` value is updated by reference every 50ms.
console.log(approximateTime.now);

```

## Sequence guarantee

It is guaranteed that two consequent attempts to retrieve time within the same 50ms time window will have unique values, i.e.

Assuming that the current time is `0000000000000`, then:

```js
approximateTime.now; // 0000000000000
approximateTime.now; // 0000000000001
approximateTime.now; // 0000000000002

```

However, if `approximateTime.now` is accessed more than 50 times within the same 50ms time window, then the top-most value within that interval is returned repeatedly.

```js
approximateTime.now; // 0000000000000
approximateTime.now; // 0000000000001
approximateTime.now; // 0000000000002

// approximateTime.now x 50
approximateTime.now; // 0000000000050
approximateTime.now; // 0000000000050
approximateTime.now; // 0000000000050

```

## benchmark

```
Date.now()          x 19,900,411 ops/sec ±0.59% (93 runs sampled)
approximateTime.now x 82,420,291 ops/sec ±0.83% (92 runs sampled)

```

## Use cases

Any sort of time-sensitive operations when it is sufficient to retrieve an approximate timestamp, e.g. [`roarr`](https://github.com/gajus/roarr) logger uses `approximate-now` to record the time when a log message was produced.

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