# time-hash

> UTC/GMT Time Hash for milliseconds/timestamps

Latest version **1.2.2** (published 2017-11-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install time-hash
pnpm add time-hash
yarn add time-hash
bun add time-hash
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2017-11-04 |
| First published | 2017-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=5.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | LoreFolk |
| Maintainers | disarticulate |
| Keywords | efficient time, time hashing, timestamps, big data |

## Links

- npm: https://www.npmjs.com/package/time-hash
- Repository: https://github.com/disarticulate/time-hash
- Homepage: https://github.com/disarticulate/time-hash/
- Issues: https://github.com/disarticulate/time-hash/issues
- npm.io page: https://npm.io/package/time-hash

## Dependencies (2)

- [decimal.js](https://npm.io/package/decimal.js.md) ^7.2.3
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.11.6

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.2.2 (latest) — 2017-11-04
- 1.2.1 — 2017-11-03
- 1.2.0 — 2017-11-03
- 1.1.1 — 2017-10-08
- 1.1.0 — 2017-10-08
- 1.0.7 — 2017-09-05
- 1.0.6 — 2017-09-05
- 1.0.5 — 2017-09-05
- 1.0.4 — 2017-09-04
- 1.0.3 — 2017-09-04
- 1.0.2 — 2017-09-04
- 1.0.0 — 2017-09-04

## README

timehash
========

About
-----

> timehash is an algorithm (with multiple reference implementations) for calculating variable precision sliding windows of time. When performing aggregations and correlations on large-scale data sets, the ability to convert precise time values into 'malleable intervals' allows for many novel analytics. 

> Using `[sliding windows of time](http://stackoverflow.com/questions/19386576/sliding-window-over-time-data-structure-and-garbage-collection) is a common practice in data analysis but prior to the timehash algorithm it was more of an art than a science. -- [abeusher/timehash](https://github.com/abeusher/timehash)

Installation
------------

`npm install time-hash -s`

`npm install`

`npm run:cover`

Usage
-------------
### Version 1.2.0 Update
> Improved browser compatability in Rollup

### Version 1.1.1 Update
```
    timehash.encodems(new Date().getTime()) // encodes from milliseconds epoch instead of timeseconds
    timehash.decodems('000000000b') // decodes to milliseconds epoch instead of timeseconds
```
> reason: Better compatability with Javascript Date() functions
### Version 1.0

```
    var TimeHash = require('time-hash') // or import TimeHash from 'time-hash'

    let timehash = new TimeHash()

    let [begin, cease] = ['1970-01-01 00:00:00 GMT', '2098-01-01 00:00:00 GMT'] // should use UTC/GMT
    
    let begin_input = new Date(begin) 
    let pivot_input = new Date('2034-01-01 00:00:00 GMT') 
    let cease_input = new Date(cease)

    let begin_hash = timehash.encode_from_datetime(begin_input)
    let pivot_hash = timehash.encode_from_datetime(pivot_input)
    let cease_hash = timehash.encode_from_datetime(cease_input)

    `${begin_hash}`
    '0000000000'
    
    `${pivot_hash}`
    'bfffffffff'
    
    `${cease_hash}`
    'ffffffffff'
    
    begin_hash_after = timehash.after(begin_hash)
    `${begin_hash_after}`
    '0000000001'
    `${timehash.before(begin_hash_after)}` === begin_hash

    let [neighbor_before, neighbor_after] = timehash.neighbors('000000000a')
    `${timehash.before(neighbor_before)}` === begin_hash
    `${neighbor_after}` === '000000000b'

    let input = '000000000a'
    let expand = timehash.expand(input)
    let [expand_before, input_clone, expand_after] = expand
    `${expand_before}` === timehash.before(input_clone)
    `${expand_after}` === timehash.after(input_clone)

    let [begin_value, begin_error] = timehash.decode_exactly('0000000000')
    new Date(begin_value - begin_error).toString() === begin_input.toString()

```

Other Compatible Implementations
---------------

-  python [timehash](https://github.com/abeusher/timehash/blob/master/timehash/__init__.py)
   - a reference implementation in pure python
-  perl [timehash](https://github.com/abeusher/timehash/blob/master/timehash.pl)
   - a reference implementation in perl
-  java [timehash](https://github.com/abeusher/timehash/blob/master/TimeHash.java)
   - a reference implementation in java

### License

Copyright © 2017 LoreFolk, LLC. This source code is licensed under the MIT license found in
the [LICENSE.txt](https://github.com/kriasoft/react-starter-kit/blob/master/LICENSE.txt) file.
The documentation to the project is licensed under the [CC BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/)
license.


---
Reference implement made with ♥ by Abe Usher [Abe Usher](https://github.com/abeusher) and [contributors] (https://github.com/abeusher/timehash/blob/master/CONTRIBUTORS.md)

Testing/DepoymentTemplate made with ♥ by Konstantin Tarkus ([@koistya](https://twitter.com/koistya)) and [contributors](https://github.com/kriasoft/babel-starter-kit/graphs/contributors)

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