time-chainer
v0.1.1
Published
Create your milliseconds declaratively!
Downloads
26
Maintainers
Readme
Time Chainer
Create your milliseconds declaratively!
Install
npm install --save time-chainer
or
yarn add time-chainer
Example
import Time from 'time-chainer';
// Do something after 5 seconds
setTimeout(() => {
doSomething();
}, +Time.seconds(5));
// 3 Days and 12 hours later from now
new Date(
new Date() + (
Time
.days(3)
.hours(12)
)
);
// 1 week + 15 days + 12 hours + 30 minutes + 30 seconds + 500 milliseconds
Time
.milliseconds(500)
.seconds(30)
.minutes(30)
.hours(12)
.days(15)
.weeks(1)
; // 1,945,830,500
TimeChainer
extends Number
Time Chainer extends Number
object. In cases where a primitive number is strictly required, you will need to explicitly convert it to a primitive number
by appending a +
operator like this:
jest.advanceTimersByTime(+Time.days(30));
See details:
Time.seconds(5) instanceof Number // true
typeof Time.seconds(5) // "object"
typeof +Time.seconds(5) // "number"