Skip to content

zewish/msec

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

msec

string to milliseconds parser

Usage

'use strict';

let msec = require('msec');

setTimeout(() => {
    console.log('I execute after 1d 2h 37m 15s');
}, msec('1d 2h 37m 15s'));

setInterval(() => {
    console.log('I execute every 2 hours');
}, msec('2h'));

setTimeout(() => {
    console.log('I execute after 1h 3m 15s');
}, msec('5s 10s 1h 3m'));

new Date(Date.now() + msec('2d')); // same time, 2 days later

new Date(Date.now() + msec('2d 4h')); // 2 days and 4 hours later

Install

$ npm install --save msec

Test

$ npm install && npm test