Easily format the time from node.js `process.hrtime`. Works with timescales ranging from weeks to nanoseconds.
Installations
npm install pretty-time
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=4
Node Version
10.0.0
NPM Version
6.1.0
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
Download Statistics
Total Downloads
268,173,816
Last Day
91,637
Last Week
571,690
Last Month
4,197,854
Last Year
55,072,250
GitHub Statistics
52 Stars
24 Commits
3 Forks
5 Watching
1 Branches
2 Contributors
Bundle Size
1.15 kB
Minified
662.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.1.0
Package Id
pretty-time@1.1.0
Size
3.82 kB
NPM Version
6.1.0
Node Version
10.0.0
Publised On
12 Jul 2018
Total Downloads
Cumulative downloads
Total Downloads
268,173,816
Last day
-17.3%
91,637
Compared to previous day
Last week
-40.2%
571,690
Compared to previous week
Last month
-10.4%
4,197,854
Compared to previous month
Last year
-7.7%
55,072,250
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
2
pretty-time
Easily format the time from node.js
process.hrtime
. Works with timescales ranging from weeks to nanoseconds.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install
Install with npm:
1$ npm install --save pretty-time
Usage
1var pretty = require('pretty-time'); 2 3var start = process.hrtime(); 4var time = process.hrtime(start); 5console.log(pretty(time)); 6//=> 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:
1pretty([1200708, 795428088]); 2//=> '2w' 3 4pretty([800708, 795428088]); 5//=> '1w' 6 7pretty([400708, 795428088]); 8//=> '5d' 9 10pretty([70708, 795428088]); 11//=> '20h' 12 13pretty([12708, 795428088]); 14//=> '4h' 15 16pretty([3708, 795428088]); 17//=> '1h' 18 19pretty([208, 795428088]); 20//=> '3m' 21 22pretty([20, 795428088]); 23//=> '21s' 24 25pretty([0, 795428088]); 26//=> '795ms' 27 28pretty([0, 000428088]); 29//=> '428μs' 30 31pretty([0, 000000088]); 32//=> '88ns' 33 34pretty([0, 000000018]); 35//=> '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
1pretty(time, 'h'); 2//=> '2h' 3 4pretty(time, 'm'); 5//=> '1h 52m' 6 7pretty(time, 's'); 8//=> '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
About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running Tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
1$ npm install && npm test
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
Related projects
You might also be interested in these projects:
- o-clock: Simple javascript utility for displaying the time in 12-hour clock format. | homepage
- seconds: Get the number of seconds for a minute, hour, day and week. | homepage
- time-stamp: Get a formatted timestamp. | homepage
- timescale: Convert from one time scale to another. Nanosecond is the most atomic unit, week is… more | homepage
- week: Get the current week number. | homepage
- weekday: Get the name and number of the current weekday. Or get the name of the… more | homepage
- year: Simple utility to get the current year with 2 or 4 digits. | homepage
Contributors
Commits | Contributor |
---|---|
14 | jonschlinkert |
5 | doowb |
Author
Jon Schlinkert
License
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on July 12, 2018.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/22 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 3 are checked with a SAST tool
Score
3
/10
Last Scanned on 2024-12-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More