Time-lord
Work with timestamps in a specific format. Works in Node.js as well as in browsers (agnostic).
Idea
I actually needed such a thing for a private project. It is a pretty cool idea, look:
var someConfigurationObject = { someTimestamp: "5h 20m 30s", // => 5 hours, 20 minutes and 30 seconds (ago).};
So here is what I came to:
var timestamp = "1y 2mo 15d 10h 23m 30s 240ms", timeLord = require("time-lord");// If you are using it on client side (browser), timeLord will be already available in `window` scope. timeLord.parse(timestamp);// => {years: 1, months: 2, days: 15, hours: 10, mins: 23, secs: 30, ms: 240} timeLord.forHumans(timestamp);// => "1 year, 2 months, 15 days, 10 hours, 23 minutes, 30 seconds and 240 milliseconds" timeLord.toSeconds(30, "s");// => 1800 timeLord.toSeconds("30s");// => 1800 timeLord.map(timeLord.parse(timestamp), {secs: "seconds", mins: "minutes"});// => { ... seconds: 30, minutes: 23}
Installation
For usage:
npm install time-lord
For development:
git clone https://github.com/bound1ess/time-lord.gitcd time-lordnpm install
Tests
grunt test
Code minification
grunt minify-js# Check out dist/ directory.
Code coverage
Aiming for 100%.
npm run get-coverage# Check out coverage/ directory.
License
MIT.