https://github.com/amoshydra/time-chainer
Create your milliseconds declaratively!
https://github.com/amoshydra/time-chainer
chaining duration milliseconds time
Last synced: 6 months ago
JSON representation
Create your milliseconds declaratively!
- Host: GitHub
- URL: https://github.com/amoshydra/time-chainer
- Owner: amoshydra
- License: mit
- Created: 2019-02-01T11:23:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-08T13:51:30.000Z (over 1 year ago)
- Last Synced: 2024-04-14T13:55:32.425Z (over 1 year ago)
- Topics: chaining, duration, milliseconds, time
- Language: JavaScript
- Homepage: https://npm.runkit.com/time-chainer
- Size: 220 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Time Chainer
Create your milliseconds declaratively](https://circleci.com/gh/amoshydra/time-chainer)
[](https://snyk.io/test/github/amoshydra/time-chainer?targetFile=package.json)
[](https://codeclimate.com/github/amoshydra/time-chainer/maintainability)
[](https://codecov.io/gh/amoshydra/time-chainer)[](https://www.npmjs.com/package/time-chainer)
# Install
```sh
npm install --save time-chainer
```or
```sh
yarn add time-chainer
```# Example
```js
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:
```js
jest.advanceTimersByTime(+Time.days(30));
```See details:
```js
Time.seconds(5) instanceof Number // true
typeof Time.seconds(5) // "object"
typeof +Time.seconds(5) // "number"
```