Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moeriki/node-millis
Millis is a set of functions that converts different measures (minutes, hours, etc..) to milliseconds.
https://github.com/moeriki/node-millis
Last synced: 22 days ago
JSON representation
Millis is a set of functions that converts different measures (minutes, hours, etc..) to milliseconds.
- Host: GitHub
- URL: https://github.com/moeriki/node-millis
- Owner: moeriki
- License: mit
- Created: 2016-09-15T07:40:14.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-17T07:21:57.000Z (over 5 years ago)
- Last Synced: 2024-12-26T01:02:36.571Z (30 days ago)
- Language: JavaScript
- Homepage:
- Size: 103 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
millis
Convert different measures (minutes, hours, etc..) to milliseconds.
---
Because code is read by humans we don't like this.
```javascript
const CACHE_TIMEOUT = 30 * 24 * 60 * 60 * 1000;const COOKIE_EXPIRE = Date.now() + 1209600000;
```But we do like this.
```javascript
import { days } from 'millis'const CACHE_TIMEOUT = days(30)
const COOKIE_EXPIRE = Date.now() + 14 * days();
```## Install
```sh
npm install --save millis
```## Import
```javascript
const seconds = require('millis/seconds');
const minutes = require('millis/minutes');
const hours = require('millis/hours');
const days = require('millis/days');
const weeks = require('millis/weeks');
const months = require('millis/months');
const years = require('millis/years');
```**ES Modules**
```javascript
import { seconds, minutes, hours, days, weeks, months, years } from 'millis';
```## Usage
```javascript
const THIRTY_SECONDS = seconds(30);
const SIX_HOURS = 6 * hours();
const TWO_DAYS_AND_TWO_HOURS = 2 * days() + 2 * hours();
```All methods are available in singular and plural.
```javascript
const year = require('millis/year');
const ONE_YEAR = year();
```### In seconds
Because often timestamps are in unix format. You might need your duration in seconds instead of milliseconds.
```javascript
const hours = require('millis/hours');
const unix = require('millis/unix');
const ONE_YEAR = 2 * unix() * hours();
```### Extending Number prototype
If you don't understand the implication of extending a native prototype \[[1](http://perfectionkills.com/extending-native-builtins/)\] \[[2](http://stackoverflow.com/questions/14034180/why-is-extending-native-objects-a-bad-practice)\], don't use this.
```javascript
require('millis/register');const TWO_DAYS = (2).days();
const SIX_HOURS = (6).unix().hours();
```