
Company News
Socket Joins the OpenJS Foundation
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.
Utility for converting textual time periods to time units
In development
First install the package and save it to package.json using npm:
npm install --save to-time
To require in the browser:
<script src="node_modules/to-time/lib/to-time.min.js"></script>
To require when using NodeJS:
const toTime = require('to-time');
Converting from textual time period to time units
toTime('1 hour').seconds(); //3600
//same as:
toTime('1h').seconds(); //3600
toTime('1 Year 365 Days 4 Hours').hours(); //17524
//same as:
toTime('1y 365d 4h').hours(); //17524
Useful for usage in methods such as setInterval and setTimeout which consume the intervals in milliseconds
//Instead of using 43200000 milliseconds (equivalent to 12 hours) we can do the following
setInterval(() => {
//Do something here
}, toTime('12h').ms());
//Instead of using 5400000 milliseconds (equivalent to 1.5 hour)
setTimeout(() => {
//Do something here
}, toTime.addHours(1.5).ms());
toTime.fromHours(4).addMinutes(30).hours(); //4.5
toTime.fromYears(4).addWeeks(4).days(); //1488
Make sure to write tests, run new & existing tests using:
npm run test
Check for source code & tests code styling by running eslint:
npm run lint
If tests are passing and eslint doesn't return any error -> Create pull request
MIT
FAQs
Utility for converting textual time periods to time units
The npm package to-time receives a total of 29,441 weekly downloads. As such, to-time popularity was classified as popular.
We found that to-time demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.

Security News
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.