# pretty-time [![NPM version](https://badge.fury.io/js/pretty-time.svg)](http://badge.fury.io/js/pretty-time)  [![Build Status](https://travis-ci.org/jonschlinkert/pretty-time.svg)](https://travis-ci.org/jonschlinkert/pretty-time)

> Easily format the time from node.js `process.hrtime`. Works with timescales ranging from weeks to nanoseconds.

## Install

Install with [npm](https://www.npmjs.com/)

```sh
$ npm i pretty-time --save
```

## Usage

```js
var pretty = require('pretty-time');

var start = process.hrtime();
var time = process.hrtime(start);
console.log(pretty(time));
//=> 3μs
```

## API

By default, when no time increment is given as the second argument, the closest timescale is used (e.g. _most granular without being less than zero_).

**Examples:**

```js
pretty([1200708, 795428088]);
//=> '2w'

pretty([800708, 795428088]);
//=> '1w'

pretty([400708, 795428088]);
//=> '5d'

pretty([70708, 795428088]);
//=> '20h'

pretty([12708, 795428088]);
//=> '4h'

pretty([3708, 795428088]);
//=> '1h'

pretty([208, 795428088]);
//=> '3m'

pretty([20, 795428088]);
//=> '21s'

pretty([0, 795428088]);
//=> '795ms'

pretty([0, 000428088]);
//=> '428μs'

pretty([0, 000000088]);
//=> '88ns'

pretty([0, 000000018]);
//=> '18ns'
```

### Minimum time increment

_(All of the following examples use `[6740, 795428088]` as the hrtime array.)_

This value is passed as the second argument and determines how granular to make the time.

**Examples**

```js
pretty(time, 'h');
//=> '2h'

pretty(time, 'm');
//=> '1h 52m'

pretty(time, 's');
//=> '1h 52m 21s'
```

**Valid time increments**

Any of the following may be used:

* `ns` | `nano` | `nanosecond` | `nanoseconds`
* `μs` | `micro` | `microsecond` | `microseconds`
* `ms` | `milli` | `millisecond` | `milliseconds`
* `s` | `sec` | `second` | `seconds`
* `m` | `min` | `minute` | `minutes`
* `h` | `hr` | `hour` | `hours`
* `d` | `day` | `days`
* `w` | `wk` | `week` | `weeks`

## Related projects

* [o-clock](https://www.npmjs.com/package/o-clock): Simple utility for displaying the time in 12-hour clock format. | [homepage](https://github.com/jonschlinkert/o-clock)
* [seconds](https://www.npmjs.com/package/seconds): Get the number of seconds for a minute, hour, day and week. | [homepage](https://github.com/jonschlinkert/seconds)
* [time-stamp](https://www.npmjs.com/package/time-stamp): Get a formatted timestamp. | [homepage](https://github.com/jonschlinkert/time-stamp)
* [timescale](https://www.npmjs.com/package/timescale): Convert from one time scale to another. Nanosecond is the most atomic unit, week is… [more](https://www.npmjs.com/package/timescale) | [homepage](https://github.com/jonschlinkert/timescale)
* [week](https://www.npmjs.com/package/week): Get the current week number. | [homepage](https://github.com/jonschlinkert/week)
* [weekday](https://www.npmjs.com/package/weekday): Get the name and number of the current weekday. Or get the name of the… [more](https://www.npmjs.com/package/weekday) | [homepage](https://github.com/jonschlinkert/weekday)
* [year](https://www.npmjs.com/package/year): Simple utility to get the current year with 2 or 4 digits. | [homepage](https://github.com/jonschlinkert/year)

## Running tests

Install dev dependencies:

```sh
$ npm i -d && npm test
```

## Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/pretty-time/issues/new).

## Author

**Jon Schlinkert**

+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)

## License

Copyright © 2015 Jon Schlinkert
Released under the MIT license.

***

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 18, 2015._